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

思路:先计算最宽的面积,当中间每一个容器高度小于当前两端最低点时,肯定是不符合条件的,因为宽也减少了,略过即可。

leetcode个人题解——#11 Container with most water的更多相关文章

  1. LeetCode Array Medium 11. Container With Most Water

    Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...

  2. 《LeetBook》leetcode题解(11):Container With Most Water[M] ——用两个指针在数组内移动

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  3. 【LeetCode two_pointer】11. Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  4. leetcode个人题解——#5 Container with most water

    class Solution { public: string longestPalindrome(string s) { int length = s.length(); ) return s; ; ...

  5. leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II

    11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情 ...

  6. Leetcode 11. Container With Most Water(逼近法)

    11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...

  7. 刷题11. Container With Most Water

    一.题目说明 11.Container With Most Water,这个题目难度是Medium. 二.我的做法 乍一看,简单啊,两个for循环就可以了,我在本地写的. #include<io ...

  8. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

  9. [leecode]---11.container with most water

    description: Input: [1,8,6,2,5,4,8,3,7]Output: 49 思路1: 从(1,a1)开始向后算面积,需要两层n循环,时间复杂度n2 思路2: 找出数组中最大的数 ...

随机推荐

  1. 聊聊c#与Python以及IronPython

    简单说说这个意义.做了很久的c#,突然发现Python火了.就看看,估计这篇博文有点长,有点长,尽量包括主要的东西,还有点杂,浏览吧,选择自己喜欢的看看. 先看比较.网上一堆各种比较.但是主要比较语法 ...

  2. 『ACM C++』 PTA 天梯赛练习集L1 | 050-51

    加油加油,努力刷题 ------------------------------------------------L1-050------------------------------------ ...

  3. ubuntu18.04安装搜狗输入法

    首先,安装Fcitx输入框架 sudo apt install fcitx 其次,上搜狗输入法官网下载Linux版本搜狗输入法(32位和64位根据自己情况,在虚拟机上用浏览器下载即可 然后进入相应的下 ...

  4. 利用MyFlash闪回丢失数据

          MyFlash is an open source tool released by Meituan-Dianping which can be used to flashback MyS ...

  5. python2.7+PyQt4+eric6 界面开发环境配置

    1.安装环境: python2.7 PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x64.exe eric6-18.12.zip 2.安装步骤: 1.安装python2.7的过程略 2 ...

  6. echarts 多图任意布局案例

    随着文档的更新,布局越来越个性化,完全可以替代整个元素界面,随意布局展示数据,下面发布一个小的文件 源码文件:https://files.cnblogs.com/files/mobeisanghai/ ...

  7. springboot的junit4模拟request、response对象

    关键字: MockHttpRequest.Mock测试 问题: 在模拟junit的request.response对象时,会报如下空指针异常. 处理方法: 可用MockHttpServletReque ...

  8. IOS移动端(H5)alert/confirm提示信息去除url

    前几天写移动端项目用alert和confirm进行信息提示,但发现在iOS系统中,每次提示信息上面都会被添加一行URL地址,安卓却没有,经过查找之后,果然不出所料,兼容!!兼容!!!兼容!!! 需要重 ...

  9. composer 基本概念与常用命令总结

    目录 composer 基本概念与常用命令总结 基本概念 软件安装 linux/mac安装 windows 配置镜像 如何使用 常用命令 全局参数 初始化 init 初始化参数 依赖安装 instal ...

  10. 关于instanceof的使用

    测试单独一个类: <?php class A { } $a = new A(); if($a instanceof A){ echo "对象\$a实现了A类"; } 当一个子 ...