Skip to content

Commit 1ef7736

Browse files
authored
Merge pull request #906 from HerrineKim/main
2 parents a41c907 + c2bf12a commit 1ef7736

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
2+
// ๊ณต๊ฐ„๋ณต์žก๋„: O(1)
3+
4+
/**
5+
* @param {number[]} height
6+
* @return {number}
7+
*/
8+
var maxArea = function (height) {
9+
let maxWater = 0;
10+
let left = 0;
11+
let right = height.length - 1;
12+
13+
while (left < right) {
14+
const lowerHeight = Math.min(height[left], height[right]);
15+
const width = right - left;
16+
maxWater = Math.max(maxWater, lowerHeight * width);
17+
18+
if (height[left] < height[right]) {
19+
left++;
20+
} else {
21+
right--;
22+
}
23+
}
24+
25+
return maxWater;
26+
};

โ€Žvalid-parentheses/HerrineKim.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
2+
// ๊ณต๊ฐ„๋ณต์žก๋„: O(n)
3+
4+
// ์Šคํƒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ด„ํ˜ธ์˜ ์œ ํšจ์„ฑ์„ ๊ฒ€์‚ฌ
5+
// ๊ด„ํ˜ธ๊ฐ€ ์—ด๋ฆฌ๋ฉด ์Šคํƒ์— ์ถ”๊ฐ€ํ•˜๊ณ  ๋‹ซํžˆ๋ฉด ์Šคํƒ์—์„œ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ๊บผ๋‚ด์„œ ์ง์ด ๋งž๋Š”์ง€ ํ™•์ธ
6+
// ์Šคํƒ์ด ๋น„์–ด์žˆ์œผ๋ฉด ์œ ํšจํ•œ ๊ด„ํ˜ธ ๋ฌธ์ž์—ด
7+
8+
/**
9+
* @param {string} s
10+
* @return {boolean}
11+
*/
12+
var isValid = function (s) {
13+
const bracketStack = [];
14+
const bracketPairs = {
15+
')': '(',
16+
'}': '{',
17+
']': '['
18+
};
19+
20+
for (const char of s) {
21+
if (char in bracketPairs) {
22+
const lastChar = bracketStack.pop();
23+
24+
if (lastChar !== bracketPairs[char]) {
25+
return false;
26+
}
27+
} else {
28+
bracketStack.push(char);
29+
}
30+
}
31+
32+
return bracketStack.length === 0;
33+
};

0 commit comments

Comments
ย (0)