LeetCode Q11 Container With Most Water

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution
{
public int maxArea(int[] height)
{
//initialize area, most left side and right side
int area = 0, l = 0, r = height.length - 1;
//as long as left is on the "left"
while(l < r)
{
area = Math.max(area, Math.min(height[l], height[r]) * (r - l));
if(height[l] < height[r])
{
l++;
}
else
{
r--;
}
}
return area;

}
}