LeetCode-11. 盛最多水的容器(Container With Most Water)

双指针

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

题目链接:https://leetcode-cn.com/problems/container-with-most-water/

发布了42 篇原创文章 · 获赞 2 · 访问量 1426

猜你喜欢

转载自blog.csdn.net/Listen_heart/article/details/102895938