Given n non-negative integers a1a2, ..., an, where each represents a point at coordinate (iai). n vertical lines are drawn such that the two endpoints of line i is at (iai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.

Note: You may not slant the container.

Solution 1:

class Solution
{
public:
int maxArea(vector<int>& height)
{
int v = INT_MIN, area;
int start = , end = height.size() - ;
while(start < end)
{
area = min(height[start], height[end]) * (end - start);
v = max(v, area);
if(height[start] < height[end]) ++start;
else --end;
}
return v;
}
};

Container With Most Water -- LeetCode 11的更多相关文章

  1. Container With Most Water - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Container With Most Water - LeetCode 注意点 没什么好注意的... 解法 解法一:暴力求解,假设任意两个端点会是最佳答 ...

  2. Container With Most Water——LeetCode

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

  3. Container With Most Water leetcode java

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

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

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

  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. LeetCode Array Medium 11. Container With Most Water

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

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

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

  9. leetcode面试准备:Container With Most Water

    leetcode面试准备:Container With Most Water 1 题目 Given n non-negative integers a1, a2, ..., an, where eac ...

随机推荐

  1. Tomcat部署web应用程序

    对Tomcat部署web应用的方式总结,常见的有以下四种: 1.[替换ROOT目录] 最简单的一种方法,webapps目录下面ROOT文件夹的文件为你的文件,然后输入localhost:8080/首页 ...

  2. Mindmanager安装

  3. python安装supervisor

    1.下载supervisor-3.3.1.tar.gz    http://pan.baidu.com/s/1dEPhGEd 2.下载meld3-1.0.2.tar.gz   http://pan.b ...

  4. JAVA数据转换常用方法

    时间格式化与运算 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar=sdf. ...

  5. 解析提高PHP执行效率的50个技巧

    1.用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量, 单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的”函数”(译注:PHP手 ...

  6. [转]CSS3 Media Query实现响应布局

    讲到响应式布局, 相信大家都有一定的了解,响应式布局是今年很流行的一个设计理念,随着移动互联网的盛行,为解决如今各式各样的浏览器分辨率以及不同移动设备的显示效果, 设计师提出了响应式布局的设计方案.今 ...

  7. Python 的 pyinotify 模块 监控文件夹和文件的变动

    官方参考: https://github.com/seb-m/pyinotify/wiki/Events-types https://github.com/seb-m/pyinotify/wiki/I ...

  8. 更新Mac OSX XCode后Git 不能使用提示Can't start Git: /usr/bin/git

    更新Mac OSX XCode后Git 不能使用提示Can't start Git: /usr/bin/git 解决办法: 终端运行 sudo xcodebuild -license 同意协议就好了.

  9. redis-JedisPoolConfig配置

    项目之前要使用redis这个临时缓存,下面是从别的大神那里转来的一些基本配置属性的说明:   JedisPoolConfig config = new JedisPoolConfig(); //连接耗 ...

  10. S3C6410开发板开发环境的搭建

    本节主要介绍了S3C6410开发板及OK6410开发板.OK6410开发板是基于ARM11处理器的S3C6410,采用“核心版+底板”结构 主要步骤如下:. OK6410开发板自带一个串口,PC也需要 ...