14、双指针——盛最多水的容器

14、双指针——盛最多水的容器_第1张图片

public int maxArea(int[] height) {
        int low = 0, high = height.length-1, temp = 0, max = 0;
        while(low < high){
           if(height[low] < height[high]){
               temp = (high-low) * height[low];
               low++;
           }
            else{
                 temp = (high-low) * height[high];
                 high--;
            }
           if(temp > max){
           max = temp;
           }
        }
        return max;
    }

你可能感兴趣的:(leetcode,算法,职场和发展)