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. 两个div叠加触发事件发生闪烁问题

    今天遇到一个问题,想实现一个功能: 当鼠标移到div1上的时候,会出现div2.出现时div2在div1的上面,div2在出现后发生闪烁的问题. 于是开始找问题根源,发现原来是因为当我们触发div1的 ...

  2. AutoCAD2006启动慢解决方案

    一. 1.打开控制面板.2.选择Internet选项.3.在Internet属性对话框里,点高级标签.4.清除“检查发行商的证书吊销”选项.5.单击应用,然后单击OK.6.重新启动,运行应用程序. 二 ...

  3. DataTable Linq Example

    DataTable CreateTable() { DataTable dtable = new DataTable(); DataColumn dc; //MId CId FId PId dc = ...

  4. Web cookie 详解

    总结:服务端客户端变量建议都是用 utf-8字符集, 前后传递的变量都建议使用url编码处理.php setcookie 保存到客户端的变量会自动url编码的, 所以客户端获取后需要decodeURI ...

  5. LNAMP服务器环境搭建(手动编译安装)

    LNAMP服务器环境搭建(手动编译安装) 一.准备材料 阿里云主机一台,操作系统CentOS 6.5 64位 lnamp.zip包(包含搭建环境所需要的所有软件) http://123.56.144. ...

  6. 大米网赚项目介绍,官方唯一客服QQ:712994168

    大米平台项目来源   QQ:712994168 大米软件本质上是一个高质量网赚项目收集和发布平台,该平台的所有项目都是经过专业的测试团队实测有效的项目和教程,只要去做绝对可以赚钱.平台里面的项目类型包 ...

  7. android模块混淆打包时,泛型丢失

    现象:lib模块中写了一个泛型接口,在混淆之后泛型消失,提示"Error:(67, 79) 错误: 类型 ******* 不带有参数" 解决:混淆时把泛型给混淆掉了,在progua ...

  8. socket.io与redis构建实时推送

    准备工作 1:准备nodejs环境 2:使用npm工具安装 socket.io  npm install socket.io 3:下载客户端socket.io文件 解压附件中的文件 node app. ...

  9. Struts2_三种传参数方法

    1.通过属性传参数(Attr)UserAction.java package com.bebig.struts2.user.action;import com.opensymphony.xwork2. ...

  10. 一张关于docker版本的图

    今天安装了windows内测版的docker,的确是是把vitualbox换成了hyper-v,如左图,server的os 还是linux.不过之前在nanoserver上装的docker 也的确是原 ...