Skip to content

Latest commit

 

History

History
26 lines (26 loc) · 638 Bytes

File metadata and controls

26 lines (26 loc) · 638 Bytes
class Solution {
    public int maxArea(int[] height) {
        int sum=0;
        int n=height.length;
        int leftX=0;
        int rightX=n-1;
        int X;
        int Y;
         //i是水池长度值
        for (int i=n-1;i>=1;i--){
            X=i;
            Y=Math.min(height[leftX],height[rightX]);
            sum=Math.max(sum,X*Y);
            if (Y==height[leftX]){
                //不要放过一个可能是大的数值
                leftX++;
            }else {
                rightX--;
            }
        }
        return sum; 
    }
}

https://leetcode-cn.com/problems/container-with-most-water/