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 ...
随机推荐
- ios开发之 -- 自动轮播图创建
这里是oc版本的,简单记录下: 具体代码如下: 1,准备 #define FRAME [[UIScreen mainScreen] bounds] #define WIDTH FRAME.size.w ...
- Linux ulimit 命令
ulimit命令用来限制系统用户对 shell 资源的访问,常见用法如下: [root@localhost ~]$ ulimit -a # 查看当前所有的资源限制 [root@localhost ~] ...
- UE4修改自Rama的UDP通信蓝图插件
UE4.15没有提供蓝图UDP的组件,可以在网上找到一个ID叫Rama写的源代码,我把它封装成插件了(MyUdpPlugin),方便在各个UE4版本工程中使用UDP通信. 使用方式: 1.在自己的工程 ...
- C# EMS Client
从 C# 客户端连接 Tibco EMS 下面例子简要介绍 C# 客户端怎样使用 TIBCO.EMS.dll 来连接 EMS 服务器. using System; using System.Diagn ...
- iGson
头文件 #import <Foundation/Foundation.h> #import <objc/runtime.h> #import "NSString+Ut ...
- Dell、IBM服务器配置远程管理卡
author: headsen chen date: 2018-10-09 14:12:32 1,IBM的服务器: 需要在bios里边进行配置,具体配置如下: , 开机画面过完之后,按F1进入bio ...
- shell 中的()【】{}(())
本文转自:https://blog.csdn.net/taiyang1987912/article/details/39551385 shell中各种括号的作用().(()).[].[[]].{} 一 ...
- 从SVN一键对比版本
公司的部署程序太多,每次部署安装完后,还得从SVN上对比版本,手工做实在太麻烦. 比如下面的一个版本 思路: 将需要检查的部件及安装的位置.SVN相关信息写入配置文件,然后程序读取配置文件 配置文件内 ...
- java 中的String类型数据添加双引号
转义符 \ 加上引号 \" <?xml version="1.0"encoding="GBK"?> String temp = &qu ...
- java如何计算两个日期之间相差多少天?
java如何计算两个日期之间相差多少天? public static void main(String [] args) { Date now = new Date(); Calendar cal = ...