Container With Most Water--LeetCode

1.题目

Container With Most Water

2.代码

class Solution {
public:
    int maxArea(vector<int>& height) {
        int res = 0;
        int i = 0;
        int j = height.size() - 1;

        while (i < j) {
            res = max(res, min(height[i], height[j]) * (j - i));
            if(height[i] < height[j])
                ++i;
            else
                --j;
        }

        return res;
    }
};

猜你喜欢

转载自blog.csdn.net/tao_ba/article/details/78676652