Skip to content

Commit a91fa79

Browse files
committed
solve container with most water
1 parent be74398 commit a91fa79

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+
class Solution {
2+
public int maxArea(int[] height) {
3+
int maxArea = 0;
4+
int s = 0, e = height.length - 1;
5+
6+
while (s < e) {
7+
int h = Math.min(height[s], height[e]);
8+
int area = (e - s) * h;
9+
maxArea = Math.max(maxArea, area);
10+
11+
if (height[s] < height[e]) {
12+
s++;
13+
} else {
14+
e--;
15+
}
16+
}
17+
18+
return maxArea;
19+
}
20+
}
21+

0 commit comments

Comments
 (0)