11. 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) {
//two pointer
if(height == null || height.length == 0) return 0;
int max = 0, left = 0, right = height.length-1;
while(left < right){
max = Math.max(max,(right-left)*Math.min(height[left],height[right]));
if(height[left] < height[right]) left++;
else right--;
}
return max;
}
}