Skip to content

Commit 38a908f

Browse files
committed
container with most water solution
1 parent 4a5bc50 commit 38a908f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

container-with-most-water/RiaOh.js

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+
const maxArea = function (height) {
6+
let left = 0;
7+
let right = height.length - 1;
8+
let max = 0;
9+
10+
while (left < right) {
11+
const graphW = right - left;
12+
const grapghH = Math.min(height[left], height[right]);
13+
14+
max = Math.max(max, graphW * grapghH);
15+
16+
if (height[left] <= height[right]) {
17+
left++;
18+
} else {
19+
right--;
20+
}
21+
}
22+
23+
return max;
24+
};

0 commit comments

Comments
 (0)