Skip to content

Commit 0cb1c54

Browse files
authored
Merge pull request #903 from limlimjo/main
[jj7779607] Week6
2 parents fe8a960 + 9e1a880 commit 0cb1c54

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

container-with-most-water/limlimjo.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @param {number[]} height
3+
* @return {number}
4+
*/
5+
var maxArea = function (height) {
6+
// Two Pointer를 이용해서 문제를 접근해야할 것 같은데 두 포인터 중에 어떤 거를 이동시켜야하는지 이 부분이 고민이 됨.
7+
// 그래서 이 부분은 풀이 참고
8+
let maxArea = 0;
9+
let start = 0,
10+
end = height.length - 1;
11+
12+
while (start < end) {
13+
// 가로 * 세로
14+
let area = (end - start) * Math.min(height[start], height[end]);
15+
16+
maxArea = Math.max(area, maxArea);
17+
18+
// 고민했던 지점
19+
if (height[start] < height[end]) {
20+
start++;
21+
} else {
22+
end--;
23+
}
24+
}
25+
return maxArea;
26+
};
27+
28+
// 시간복잡도: O(n)
29+
// 공간복잡도: O(1)

valid-parentheses/limlimjo.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function (s) {
6+
// 괄호 관리 스택
7+
const stack = [];
8+
9+
// 여는 괄호, 닫는 괄호 매핑
10+
const brackets = { "(": ")", "{": "}", "[": "]" };
11+
12+
// for문 돌며 확인
13+
for (let i of s) {
14+
// 여는 괄호일 경우
15+
if (brackets[i]) {
16+
stack.push(brackets[i]);
17+
// 닫는 괄호일 경우
18+
} else if (stack.length === 0 || i !== stack.pop()) {
19+
return false;
20+
}
21+
}
22+
return stack.length === 0;
23+
};
24+
25+
// 시간복잡도: O(n)
26+
// 공간복잡도: O(n)

0 commit comments

Comments
 (0)