美文网首页
w2-T11 之11. 盛最多水的容器-中等

w2-T11 之11. 盛最多水的容器-中等

作者: 小院闲窗春已深 | 来源:发表于2020-05-06 13:23 被阅读0次
image.png
image.png

解法1:双指针法

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

相关文章

网友评论

      本文标题:w2-T11 之11. 盛最多水的容器-中等

      本文链接:https://www.haomeiwen.com/subject/qlgightx.html