Unknown's avatar

11. Container With Most Water

11. Container With Most Water

class Solution {
    public int maxArea(int[] height) {
        int maxArea =  Integer.MIN_VALUE;
        int l = 0;
        int r = height.length - 1;
        while(l < r){
            maxArea = Integer.max(maxArea, Integer.min(height[l],height[r])*(r-l));
            if(height[l] < height[r]) l++;
                else r--;
        }
        return maxArea;
    }
}

Leave a comment