力扣第11题 盛水最多的容器

力扣第11题 盛水最多的容器

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

猜你喜欢

转载自www.cnblogs.com/woodjay/p/12729079.html