11 Container With Most Water

public class No11 {

    public static void main(String[] args) {
        int[] height = { 3, 4, 5 ,3};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {

        int left=0;
        int right=height.length-1;
        int max=0;
        int size=0;

        while(left<right){
            size=(right-left)*Math.min(height[left], height[right]);
            max=max>size?max:size;

            if(height[left]>height[right])
                right--;
            else
                left++;
        }
        return max;

    }
}

你可能感兴趣的:(11 Container With Most Water)