Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9e1ac18

Browse files
authoredMay 11, 2025
Merge pull request #1427 from RiaOh/main
[RiaOh] Week 06 solutions
2 parents 87e5f67 + 38a908f commit 9e1ac18

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
 
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} prices
3+
* @return {number}
4+
*/
5+
var maxProfit = function (prices) {
6+
// 가장 작은 수
7+
let minNum = prices[0];
8+
// 차이 값
9+
let maxProfit = 0;
10+
for (let i = 1; i < prices.length; i++) {
11+
minNum = Math.min(minNum, prices[i - 1]); // 이전꺼 중 가장 작은 수
12+
maxProfit = Math.max(maxProfit, prices[i] - minNum);
13+
}
14+
return maxProfit;
15+
};

‎container-with-most-water/RiaOh.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {number[]} height
3+
* @return {number}
4+
*/
5+
const maxArea = function (height) {
6+
let left = 0;
7+
let right = height.length - 1;
8+
let max = 0;
9+
10+
while (left < right) {
11+
const graphW = right - left;
12+
const grapghH = Math.min(height[left], height[right]);
13+
14+
max = Math.max(max, graphW * grapghH);
15+
16+
if (height[left] <= height[right]) {
17+
left++;
18+
} else {
19+
right--;
20+
}
21+
}
22+
23+
return max;
24+
};

‎valid-parentheses/RiaOh.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function (s) {
6+
const newArr = [...s];
7+
if (newArr[0] === ")" || newArr[0] === "}" || newArr[0] === "]") {
8+
return false;
9+
}
10+
11+
for (let i = 1; i < newArr.length; i++) {
12+
if (newArr[i] === ")" && newArr[i - 1] === "(") {
13+
newArr.splice(i - 1, 2);
14+
i = i - 2;
15+
}
16+
17+
if (newArr[i] === "}" && newArr[i - 1] === "{") {
18+
newArr.splice(i - 1, 2);
19+
i = i - 2;
20+
}
21+
22+
if (newArr[i] === "]" && newArr[i - 1] === "[") {
23+
newArr.splice(i - 1, 2);
24+
i = i - 2;
25+
}
26+
}
27+
return newArr.length === 0 ? true : false;
28+
};

0 commit comments

Comments
 (0)
Please sign in to comment.