【LeetCode】盛最多水的容器

官方的题解已经很好了。

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

你可能感兴趣的:(题解,数据结构)