力扣 11.盛水最多的容器(双指针)

11. 盛最多水的容器 - 力扣(LeetCode)

代码区:

cpp 复制代码
class Solution {
public:
    int maxArea(vector<int>& height) {
        //双指针
        int left =0,right=height.size()-1;
        int maxarea=0;
        while(left<right){
            maxarea=max(maxarea,(right-left)*min(height[right],height[left]));
            if(height[left]<height[right]){
                left++;
            }else{
                right--;
            }
        }
        return maxarea;
    }
};

欢迎各位读者提出意见。

(菜菜奋斗小日记)

相关推荐
u0109272718 分钟前
模板编译期排序算法
开发语言·c++·算法
GIS瞧葩菜17 分钟前
Cesium 轴拖拽 + 旋转圈拖拽 核心数学知识
人工智能·算法·机器学习
m0_6860416123 分钟前
C++中的适配器模式变体
开发语言·c++·算法
txzrxz24 分钟前
结构体排序,双指针,单调栈
数据结构·算法·双指针算法·单调栈·结构体排序
AndrewHZ27 分钟前
【AI黑话日日新】什么是AI智能体?
人工智能·算法·语言模型·大模型·llm·ai智能体
恒者走天下28 分钟前
cpp c++辅导星球价格调整
c++
wWYy.29 分钟前
算法:二叉树最大路径和
数据结构·算法
葱明撅腚30 分钟前
利用Python挖掘城市数据
python·算法·gis·聚类
We་ct33 分钟前
LeetCode 36. 有效的数独:Set实现哈希表最优解
前端·算法·leetcode·typescript·散列表
weixin_3954489144 分钟前
main.c_cursor_0129
前端·网络·算法