Skip to content

Commit 0168f00

Browse files
committed
Added solution to container with most water written in java to the leetcode folder
1 parent 4100e9f commit 0168f00

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int maxArea(int[] height) {
3+
int left = 0;
4+
int right = height.length - 1;
5+
int maxCapacity = -1;
6+
while (left != right){
7+
int currentCapacity = (right - left)*Math.min(height[left], height[right]);
8+
if (currentCapacity > maxCapacity){
9+
maxCapacity = currentCapacity;
10+
}
11+
if (height[left] <= height[right]){
12+
left++;
13+
}
14+
else{
15+
right--;
16+
}
17+
}
18+
return maxCapacity;
19+
}
20+
}

0 commit comments

Comments
 (0)