Leetcode11-30

11. 盛最多水的容器

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

  

posted @ 2020-11-23 12:45  五岁就很帅🎈  阅读(55)  评论(0)    收藏  举报