Container With Most Water

class Solution {
public:
    int maxArea(vector& height) 
    {
        int len = height.size();
        if (len <= 1)
            return 0;
        int begin = 0 ;
        int end = len-1;
        int res = 0;
        while(begin < end)
        {
            res= max(res, min(height[begin], height[end])*(end-begin));
            if(height[begin] <= height[end])
                ++begin;
            else
                --end;
        }
        return res;
        
    }
};

你可能感兴趣的:(leetcode)