题解 | #盛水最多的容器#

盛水最多的容器

https://www.nowcoder.com/practice/3d8d6a8e516e4633a2244d2934e5aa47

class Solution {
public:
   //双指针算法
    int maxArea(vector<int>& height) 
    {
        int n=height.size();
        int left=0,right=n-1;
        int res=0;
        while(left<right)
        {
            int v=min(height[left],height[right])*(right-left);
            res=max(v,res);
            if(height[right]>height[left])left++;
            else right--;
        }
        return res;
    }
};

全部评论

相关推荐

牛客51274894...:照片认真的吗,找个专门拍证件照的几十块钱整端正点吧,要不就别加照片
点赞 评论 收藏
分享
钱嘛数字而已:辅导员肯定不能同意,不然你出事了,他要承担责任。但是,脚和脑子都长在你自己身上,使用它还需要向辅导员报告么? 辅导员必须按流程拒绝你,然后你拿出成年人的态度,做自己的选择。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务