Container With Most Water -- LeetCode 11
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) 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的更多相关文章
- Container With Most Water - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Container With Most Water - LeetCode 注意点 没什么好注意的... 解法 解法一:暴力求解,假设任意两个端点会是最佳答 ...
- Container With Most Water——LeetCode
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- Container With Most Water leetcode java
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- 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 用双指针向中间滑动,较小的高度就作为当前情 ...
- Leetcode 11. Container With Most Water(逼近法)
11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...
- LeetCode Array Medium 11. Container With Most Water
Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...
- 《LeetBook》leetcode题解(11):Container With Most Water[M] ——用两个指针在数组内移动
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- leetcode面试准备:Container With Most Water
leetcode面试准备:Container With Most Water 1 题目 Given n non-negative integers a1, a2, ..., an, where eac ...
随机推荐
- 树(三)——自平衡二叉树(AVL)
简介 自平衡二叉树(AVL)属于二叉平衡树的一类,此类树主要完成一个从键到值的查找过程,即字典(或映射),它维护树高度的方式与其他数据结构不同. 自平衡规则: AVL树的左.右子树都是AVL树 左.右 ...
- ajax 参数有中文
虽然很少会有这种情况,但是既然遇到了就记录一下.一般发请求的话如下 $.ajax({ url: "", type: 'get', data: {'name': val}, data ...
- java selenium (十三) 智能等待页面加载完成
我们经常会碰到用selenium操作页面上某个元素的时候, 需要等待页面加载完成后, 才能操作. 否则页面上的元素不存在,会抛出异常. 或者碰到AJAX异步加载,我们需要等待元素加载完成后, 才能操 ...
- java selenium (三) 环境搭建 基于Maven
现在Java的大部分项目都是基于Maven, 在Maven项目中使用Selenium2. 非常简单. 首先你需要配置好Maven的环境 可以参考本博客的Maven教程系列,Maven入门教程(一) ...
- json序列化时datetime的处理方法
.net自带的json序列化器,JavaScriptSerializer和DataContractJsonSerializer,都是序列化成微软的datetime json格式,e.g. " ...
- [并查集] POJ 1703 Find them, Catch them
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43132 Accepted: ...
- 利用WPS 2012/2013 0day针对中国政府部门的定向攻击
今天早上,我们捕获到一个利用wps 2012/2013 0day针对中国政府部门的钓鱼邮件定向攻击事件. 邮件发件人以2014中国经济形势解析高层报告组委会 标题发出,附件为包含wps2012 0da ...
- AnyCAD.NET C#开发CAD软件实践(一)
免费的AnyCAD.NET发布了!俺喜欢的C#有了大展前途的机会了. 打算用这个框架搭建一套实用的CAD系统,目标是能买出去10套以上. 先看看AnyCAD.NET的自我介绍. http://www. ...
- android学习之线性布局
效图如下 移通152余继彪 该布局使用了线性布局完成 父布局为线性布局,黄色和灰色部分为水平的线性布局,剩余50%部分为水平线性布局,该布局中包含了两个垂直的线性布局分别占了三分之1和三分之二
- jQuery中animate的height的自适应
可以用 animate() 方法几乎可以操作大部分CSS 属性,但其属性的值不能为字符串,很多人都遇到过这个问题. 例如:获取一个元素自适应时的高,但el.animate({height:‘aut ...