Skip to content

Commit ff1251b

Browse files
committed
container with most water solution
1 parent c6811d7 commit ff1251b

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+
function maxArea(height: number[]): number {
2+
const n = height.length;
3+
4+
let maximumArea = 0;
5+
let l = 0;
6+
let r = n - 1;
7+
8+
while (l < r) {
9+
const currentArea = (r - l) * Math.min(height[l], height[r]);
10+
11+
maximumArea = Math.max(maximumArea, currentArea);
12+
13+
if (height[l] > height[r]) {
14+
r--;
15+
} else {
16+
l++;
17+
}
18+
}
19+
20+
return maximumArea;
21+
}

0 commit comments

Comments
 (0)