Skip to content

Commit 43123dc

Browse files
committed
container-with-most-water
1 parent d96cdb8 commit 43123dc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
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+
var maxArea = function (height) {
6+
// ๋” ๋‚ฎ์€ ์ชฝ์„ ์•ˆ์ชฝ์œผ๋กœ ์ด๋™ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ
7+
8+
let start = 0;
9+
let end = height.length - 1;
10+
let res = -1;
11+
while (start <= end) {
12+
const v = Math.min(height[start], height[end]) * (end - start);
13+
if (v > res) {
14+
res = v;
15+
}
16+
17+
if (height[start] > height[end]) {
18+
end -= 1;
19+
} else {
20+
start += 1;
21+
}
22+
}
23+
return res;
24+
};

0 commit comments

Comments
ย (0)