首页 > 其他分享 >LeetCode盛最多水的容器(/双指针)

LeetCode盛最多水的容器(/双指针)

时间:2023-01-26 23:44:11浏览次数:55  
标签:area int 题解 height ans 最多水 LeetCode 指针

原题解

题目

约束

题解

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

标签:area,int,题解,height,ans,最多水,LeetCode,指针
From: https://www.cnblogs.com/chuixulvcao/p/17068407.html

相关文章