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 ...
随机推荐
- 当singleton Bean依赖propotype Bean,可以使用在配置Bean添加look-method来解决
在Spring里面,当一个singleton bean依赖一个prototype bean,因为singleton bean是单例的,因此prototype bean在singleton bean里面 ...
- Python 入门(一)定义字符串+raw字符串与多行字符串
定义字符串 前面我们讲解了什么是字符串.字符串可以用''或者""括起来表示. 如果字符串本身包含'怎么办?比如我们要表示字符串 I'm OK ,这时,可以用" " ...
- nutch 存储到数据库
就像我们知道的一样,nutch是一个架构在lucene之上的网络爬虫+搜索引擎. 是由lucene的作者在lucene基础之上开发,并整合了hadoop,实现在分布式云计算,使用google标准的HF ...
- mysql 数据表读锁机制详解
为了给高并发情况下的mysql进行更好的优化,有必要了解一下mysql查询更新时的锁表机制.一.概述MySQL有三种锁的级别:页级.表级.行级.MyISAM和MEMORY存储引擎采用的是表级锁(tab ...
- golang 小知识-持续更新中
Golang 中的指针 - Pointer Go 的原生数据类型可以分为基本类型和高级类型,基本类型主要包含 string, bool, int 及 float 系列,高级类型包含 struct,ar ...
- 静态资源的gzip
1.项目中,接触到gzip.未压缩的文件和压缩后的文件的比例可能达到:3:1.所以,gzip是网络中文件高速传输的很好方法. 2.一般js.css.html文件都会在后端进行gzip.当浏览器请求这些 ...
- jquery类似方法的比较(一)
1. $(div + p) & $(div ~ p) & $(div p) & $(div > p) $(div + p)选择紧挨在div后面的P元素 $(div ~ p ...
- vux 局部注册组件
在home.vue里面,引入Prop.vue组件: 其中 <child :message="msg"></child>的时候 是这么赋值的: data () ...
- linux 上安装pstree
linux 无法使用pstree centos7上默认没有安装psmisc包. 1.在 Mac OS上 brew install pstree 2.在 Fedora/Red Hat/CentOS yu ...
- 用 Fiddler查看 Android 网络请求
1. 下载安装 fiddler,尽量到官方网站找最新的版本 备注:安装后,打开的时候如果报错: Machine-wide Progress Telerik Fiddler installation h ...