Skip to content

Commit 21b5059

Browse files
committed
Add week 6 solutions: container-with-most-water
1 parent 18150be commit 21b5059

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* https://leetcode.com/problems/container-with-most-water/
3+
* time complexity : O(n)
4+
* space complexity : O(1)
5+
*/
6+
export function maxArea(height: number[]): number {
7+
let s = 0, e = height.length - 1, max = 0;
8+
9+
while (s < e) {
10+
max = Math.max((e - s) * Math.min(height[s], height[e]), max);
11+
if (height[s] < height[e]) s++;
12+
else e--;
13+
}
14+
return max;
15+
};

0 commit comments

Comments
 (0)