Skip to content

Commit 77917b1

Browse files
committed
container-with-most-water solution
1 parent a92eb7e commit 77917b1

File tree

1 file changed

+21
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)