Skip to content

Commit 52d8c2a

Browse files
authored
[ PS ] : Container With Most Water
1 parent b7b6ee8 commit 52d8c2a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* μ£Όμ–΄μ§„ λ°°μ—΄μ—μ„œ (두 μ›μ†Œ 쀑 μž‘μ€ κ°’) * (두 μ›μ†Œμ˜ 인덱슀 차이)의 μ΅œλŒ“κ°’μ„ λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜
3+
* @param {number[]} height
4+
* @return {number}
5+
*/
6+
const maxArea = function(height) {
7+
let left = 0;
8+
let right = height.length - 1;
9+
let max = 0;
10+
11+
while (left < right) {
12+
const w = right - left;
13+
const h = Math.min(height[left], height[right]);
14+
15+
max = Math.max(max, w * h);
16+
17+
if (height[left] <= height[right]) {
18+
left++;
19+
} else {
20+
right--;
21+
}
22+
}
23+
24+
return max;
25+
};
26+
27+
// μ‹œκ°„λ³΅μž‘λ„: O(n)
28+
// κ³΅κ°„λ³΅μž‘λ„: O(1)

0 commit comments

Comments
Β (0)