盛最多水的容器

class Solution {
public:
    int maxArea(vector<int>& height) {
        if(height.size()==0) return 0;
        int left=0,right=height.size()-1;

        int res=INT_MIN;
        while(left<right){
            if(height[left]<height[right]){
                res=max(res,height[left]*(right-left));
                left+=1;
            }
            else{
                res=max(res,height[right]*(right-left));
                right-=1;
            }
        }
        return res; 
    }
};
posted @ 2020-03-07 16:35  7aughing  阅读(79)  评论(0编辑  收藏  举报