Given n non-negative integers a1a2, ..., an, where each represents a point at coordinate (iai). n vertical lines are drawn such that the two endpoints of line i is at (iai) 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 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(装最多的水 双指针)的更多相关文章

  1. [LeetCode] 11. Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...

  2. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  3. [LintCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  4. 11. Container With Most Water 装水最多的容器

    [抄题]: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  5. [LeetCode]11. Container With Most Water 盛最多水的容器

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...

  6. 【LeetCode】11. Container With Most Water 盛最多水的容器

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:盛水,容器,题解,leetcode, 力扣,python ...

  7. 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 用双指针向中间滑动,较小的高度就作为当前情 ...

  8. [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).  ...

  9. LeetCode Array Medium 11. Container With Most Water

    Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...

随机推荐

  1. swift - UITextField 的用法

    1,文本框的创建,有如下几个样式: public enum UITextBorderStyle : Int {     case none 无边框     case line 直线边框     cas ...

  2. 【RF库Collections测试】combine lists

    Arguments: [ *lists ]Combines the given `lists` together and returns the result. The given lists are ...

  3. CentOS5.5环境下布署LVS+keepalived

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/401253 #!/bin ...

  4. SPI接口功能描述

  5. Django学习笔记 Django的工程目录

    mysite├── manage.py 管理项目:包括数据库建立.服务器运行.测试……└── mysite    ├── __init__.py     ├── settings.py 配置文件:应用 ...

  6. MQTT的学习研究(十七)Mosquitto简要教程(安装&使用)

    Mosquitto是一个实现了MQTT3.1协议的代理服务器,由MQTT协议创始人之一的Andy Stanford-Clark开发,它为我们提供了非常棒的轻量级数据交换的解决方案.本文的主旨在于记录M ...

  7. UVa 673 Parentheses Balance (stack)

    题目描述 : 判断字符串是不是符合正确的表达式形式. 要点 : 考虑字符串为空的时候,用getline输入,每一次判断后如果为No则要清空栈.对称思想. 注意输入格式. 代码: #include &l ...

  8. kerberos认证协议分析

    Kerberos认证协议分析 Kerberos认证协议流程 如上图: * 第一步:client和认证服务器(AS)通信完成认证过程,如果认证成功AS返回给client一个TGT(用来向TGS获取tic ...

  9. net 中的一些知识

    这是一篇摘抄的文章 有一些内容对我很有帮助 .有一些内容解释很清晰 所以我拿过来了. 第一遍用了5天时间,第二遍看的时候决定自己复制一份出来于是有了这儿博客. 什么是.NET?什么是.NET Fram ...

  10. fluentValidation集成到autofac

    废话不说直接上代码 // 首先实现ValidatorFactory public class DependencyResolverValidatorFactory : ValidatorFactory ...