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 ...
随机推荐
- 关于紫光a5扫描仪的安装
同事需要扫描写东西,从别的机器上搬来紫光a5的扫描仪,不会安装,需要帮忙. 插上扫描仪,win7提示发现新硬件,开始自动安装驱动.等了一会儿,提示无法安装,看来得手工寻找驱动来安装了.上网搜索a5的驱 ...
- Jquery设置Cookie
jQuery代码: <script src="js/jquery-1.3.1.js" type="text/javascript"></scr ...
- 使用CXF发布WebService
这里普及一下WebService和cxf的知识.关于webservice和cxf: WebService.各种提供服务的组件 .企业总线.通讯总线(ESB)CXF:是一个SOA框架,Axi ...
- vue的选项
这篇是我自己看着方便整理的,请直接看官方api:http://cn.vuejs.org/v2/api/ 数据 data,props,computed 注意,不应该使用箭头函数来定义计算属性函数 (例如 ...
- [转]用CSS给SVG <use>的内容添加样式
来源:http://www.w3cplus.com/svg/styling-svg-use-content-css.html?utm_source=tuicool&utm_medium=ref ...
- C++调用约定和名字约定
C++调用约定和名字约定 转自http://www.cppblog.com/mzty/archive/2007/04/20/22349.html 调用约定:__cdecl __fastcall与 __ ...
- μC/OS-Ⅲ系统的源代码文件组织结构
- VBA唏嘘戏——简单单元格的设定(实例)
由于有很多个Word文件,所以应用宏会更加方便排版,而且版式较为统一. Sub 设置列宽() ' ' 设置列宽宏 ' ' ActiveDocument.Tables().Cell(, ).Width ...
- Object有哪些公用方法
Object是所有类的父类,任何类都默认继承Object.Object类到底实现了哪些方法? 1.clone方法 保护方法,实现对象的浅复制,只有实现了Cloneable接口才可以调用该方法,否则抛出 ...
- 【初级】linux mkdir 命令详解及使用方法实战
mkdir命令详解及使用方法实战 名称 MKDIR 是 make directories 的缩写 使用方法 mkdir [选项(如-p)] ...目录名称(及子目录注意用分隔符隔开)... 如使 ...