Skip to content

Commit e2daf9a

Browse files
authored
Create 11. Container With Most Water
1 parent c3040c4 commit e2daf9a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: 11. Container With Most Water

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class Solution {
2+
int computeArea(int left, int right, int[] heights) {
3+
return (right-left)*Math.min(heights[left], heights[right]);
4+
}
5+
6+
public int maxArea(int[] heights) {
7+
// write your code here
8+
int left = 0, ans= 0 ;
9+
int right = heights.length - 1;
10+
while(left <= right) {
11+
ans = Math.max(ans,computeArea(left, right, heights));
12+
if(heights[left]<=heights[right])
13+
left++;
14+
else
15+
right--;
16+
}
17+
return ans;
18+
}
19+
}

0 commit comments

Comments
 (0)