11. Container With Most Water(装最多的水 双指针)
Note: You may not slant the container and n is at least 2.
l = 0
r = n-1
a[l] <a[r]
l++
那边矮扔掉哪边
class Solution {
public:
int maxArea(vector<int>& a) {
const int n = a.size();
int res = ;
int low = ;
int high = n-;
while(low<=high) {
res = std::max((high-low)*std::min(a[low],a[high]),res);
if(a[low]<a[high]) {
low++;
} else {
high--;
}
}
return res;
}
};
class Solution:
def maxArea(self, a):
"""
:type height: List[int]
:rtype: int
"""
maxArea = 0
l = 0
r = len(a) - 1
while(l<r):
maxArea = max(maxArea,min(a[l],a[r])*(r-l))
if(a[l]<a[r]):
l+=1
else :
r-=1
return maxArea
11. Container With Most Water(装最多的水 双指针)的更多相关文章
- [LeetCode] 11. Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- [LintCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 11. Container With Most Water 装水最多的容器
[抄题]: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- [LeetCode]11. Container With Most Water 盛最多水的容器
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- 【LeetCode】11. Container With Most Water 盛最多水的容器
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:盛水,容器,题解,leetcode, 力扣,python ...
- 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 My Submissions Question 解题思路
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- LeetCode Array Medium 11. Container With Most Water
Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...
随机推荐
- eclipse中debug模式不能启动运行,run运行模式却能启动运行!
这个问题我郁闷了好久!问题原因:因为断点太多了,断点冲突了. 解决办法:只要进如deug界面,选择BreakPoints选项,然后清除所有断点,再重新debug启动.问题解决! 希望能帮到遇到此问题的 ...
- 【RF库Collections测试】Dictionaries Should Be Equal
Name:Dictionaries Should Be EqualSource:Collections <test library>Arguments:[ dict1 | dict2 | ...
- 说说GPIO.H(NUC131)
/**************************************************************************//** * @file GPIO.h * @ve ...
- IIS7以上版本去掉伪静态去掉index.php方法
1,由于从iis7以上的版本httpd.ini文件已不会被解析,将以下的xml文件复制到web.config 的文件中,然后放到网站的根目录即可. <?xml version="1.0 ...
- 《转》python学习(6)序列类型-字符串
转自 http://www.cnblogs.com/BeginMan/archive/2013/06/08/3125502.html 二.序列类型 包含字符串.列表.元祖.模式都一样,举一反三即可.如 ...
- 【PHP+Redis】 php-redis 操作类 封装
<?php /** * redis操作类 * 说明,任何为false的串,存在redis中都是空串. * 只有在key不存在时,才会返回false. * 这点可用于防止缓存穿透 * */ cla ...
- CentOS下安装cvechecker并进行主机基线安全检查
一.cvechecker的安装 1.首先下载cvechecker并解压该文件: cd /home/username mkdir cve wget https://raw.githubuserconte ...
- sping整合quartz
很简单,一共需要定义三个bean 需要注意的是每个bean的类型 业务bean(就是我们每次调度需要做的工作) <bean id="quantzjobBean" class= ...
- WCF(五) 深入理解绑定
适用于本机WCF-WCF交互性能最佳的绑定: 允许跨主机,但只能用于部署同一台主机上,不能访问命名管道 netNamePipeBinding总结 一 WCF与SOA SOA是一种通过为所有软件提供服务 ...
- etc/fstab
etc/fstab 就是在开机引导的时候自动挂载到linux的文件系统 设备名称 挂载点 分区的类型 挂载选项 dump选项 fsck选项UUID=ce25cdc7-434f-420b-b3 / ex ...