Skip to content

Commit 02dab0e

Browse files
committed
Add container with most water Solution = s0ooo0k
1 parent 55b2990 commit 02dab0e

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 left=0;
4+
int right=height.length-1;
5+
int max=0;
6+
7+
while(left<right) {
8+
int water = (right-left) * Math.min(height[left], height[right]);
9+
max = Math.max(max, water);
10+
11+
if(height[left]<height[right]) {
12+
left++;
13+
} else {
14+
right--;
15+
}
16+
}
17+
return max;
18+
}
19+
}
20+
21+

0 commit comments

Comments
 (0)