C++ | Leetcode C++题解之第11题盛最多水的容器

题目:

题解:

cpp 复制代码
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;
    }
};
相关推荐
rqtz几秒前
【C++】ROS2捕获Ctrl+C信号+原子操作与线程生命周期控制
c++·多线程·原子
进击的荆棘1 小时前
递归、搜索与回溯——递归
算法·leetcode·递归
老四啊laosi8 小时前
[C++进阶] 24. 哈希表封装unordered_map && unordered_set
c++·哈希表·封装·unordered_map·unordered_set
妙为9 小时前
银河麒麟V4下编译Qt5.12.12源码
c++·qt·国产化·osg3.6.5·osgearth3.2·银河麒麟v4
Billlly9 小时前
ABC 453 个人题解
算法·题解·atcoder
小白菜又菜11 小时前
Leetcode 2075. Decode the Slanted Ciphertext
算法·leetcode·职场和发展
史迪仔011212 小时前
[QML] QML IMage图像处理
开发语言·前端·javascript·c++·qt
会编程的土豆13 小时前
【数据结构与算法】再次全面了解LCS底层
开发语言·数据结构·c++·算法
低频电磁之道13 小时前
解决 Windows C++ DLL 导出类不可见的编译错误
c++·windows
君义_noip15 小时前
信息学奥赛一本通 4150:【GESP2509七级】⾦币收集 | 洛谷 P14078 [GESP202509 七级] 金币收集
c++·算法·gesp·信息学奥赛·csp-s