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. Unity 游戏框架搭建 (二十三) 重构小工具 Platform

    在日常开发中,我们经常遇到或者写出这样的代码 var sTrAngeNamingVariable = "a variable"; #if UNITY_IOS || UNITY_AN ...

  2. 阿里云修改主机名(以centOS为例)

    需要更改配置文件生效,修/etc/sysconfig/network里的 HOSTNAME=主机名(可自定义),重启生效. 如何修改? 1.[root@aliyunbaike ~]# cd /etc/ ...

  3. iOS多语言设置

    最近公司做的项目需要向国外推广,因此app需要添加相应的语言设置,为此整理记录下多语言设置的过程.如有不对的地方,欢迎各位大神指正.下面就详细介绍下设置的过程: 1.基本设置 第一步:首先在 项目工程 ...

  4. HTML如何禁止input输入

    第一种方法: 在input元素上加readonly="readonly"属性 <input type="text" readonly="read ...

  5. C++分享笔记:5X5单词字谜游戏设计

    笔者在大学二年级刚学完C++程序设计后,做过一次课程设计,题目是:5X5单词字谜游戏设计.为了设计算法并编写程序,笔者在当时颇费了一番心力,最后还是成功地完成了.设计中不乏有精妙之处.该程序设计完全是 ...

  6. 一个hibernate中的异常:NonUniqueDiscoveredSqlAliasException

    在hibernate中用SQL查询返回的结果集中,列名或别名必须唯一,否则会报下面的错误.返回的结果集中,列名或别名可以没有,但只能有一列没有. //空别名重复的情况:org.hibernate.lo ...

  7. Yii2之发送电子邮件

    官方文档:http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html 使用Yii2框架的时候,有时候需要发送电子邮件,Yiii2提供 ...

  8. jQuery 动画效果 与 动画队列

    基础效果 .hide([duration ] [,easing ] [,complete ]) 用于隐藏元素,没有参数的时候等同于直接设置 display 属性 $('.target').hide() ...

  9. Win7配置express4环境

    本机环境: $ node -v v10.14.1 $ npm -v 6.4.1 配置node环境变量: #配置全局安装目录 npm config set prefix "G:\WEB\nod ...

  10. 我的名字叫hadoop

      第一回 新入环境 我的名字是hadoop,我一出生我的爸爸雅虎就给我取了这样一个名字:hadoop,我也不知道为什么叫这个名字,刚出生没多久,雅虎爸爸就把我领进一个黑暗的屋子里面,屋里堆满了黑色的 ...