Container With Most Water
Last updated
Last updated
Input: [1,8,6,2,5,4,8,3,7]
Output: 49class Solution {
public int maxArea(int[] height) {
int l = 0, r = height.length - 1;
int res = 0;
while (l < r) {
res = Math.max(res, Math.min(height[l], height[r])*(r-l));
if (height[l] < height[r])
l++;
else
r--;
}
return res;
}
}