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 ...
随机推荐
- python2.0_day18_django_ORM
Django_ORMday15\16我们学到的ORM都是最基本的增删改查.下面我们稍作升级,学习下高级点的增删改查.先创建一个新的APP项目 python3. manage.py startapp b ...
- 全面解析Linux 内核 3.10.x - 如何开始
万事开头难 - 如何开始? 人总是对未知的事物充满恐惧!就像航海一样,在面对危难的时候,船员和船长是一样心中充满恐惧的!只是船员始终充满恐惧,而船长却能压抑恐惧并从当前找出突破口! 我没有船长之能,但 ...
- ARM、MCU、DSP、FPGA、SOC各是什么?区别是什么?(转)
ARM ARM处理器是Acorn计算机有限公司面向低预算市场设计的第一款RISC微处理器.更早称作Acorn RISC Machine.ARM处理器本身是32位设计,但也配备16位指令集,一般来讲比等 ...
- 【PHP】通过header发送自定义数据
发送header: 我们定义了三个参数,token.language.region,放入header发送过去 <?php $url = 'http://www.example.com'; $he ...
- 【linux】Crontab 定时任务 使用实例
1 使用putty 登录linux 服务器 2 输入以下命令.查看已有的定时任务 crontab -l 3 输入 以下命令,进入定时任务文件 crontab -e 4 键盘 选择 i 键 进行输 ...
- centos7 elk install :ELK 安装 6.1.2版本
参考:http://blog.csdn.net/h952520296/article/details/78873849 (参考) 官网下载:https://www.elastic.co/cn/down ...
- Video如何不自动全屏播放?
知乎:微信内置浏览器 如何小窗不全屏播放视频? 目前在微信中只能全屏播放,只有加入腾讯白名单的视频才能小屏播放. 知乎上讨论的解决方案尚未测试,太麻烦了.
- 【BZOJ4545】DQS的trie 后缀自动机+LCT
[BZOJ4545]DQS的trie Description DQS的自家阳台上种着一棵颗粒饱满.颜色纯正的trie. DQS的trie非常的奇特,它初始有n0个节点,n0-1条边,每条边上有一个字符 ...
- 【BZOJ2434】[NOI2011]阿狸的打字机 AC自动机+DFS序+树状数组
[BZOJ2434][NOI2011]阿狸的打字机 Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机.打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P ...
- nginx软件的编译安装步骤
1.1 检查软件安装的系统环境 [root@web02 conf]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@web02 co ...