LeetCode 11.Container With Most Water

8人阅读 评论(0) 收藏 举报
分类:

题目

Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) 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.

思路

双指针,每次移动高度比较小的指针。参考

代码

class Solution:
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        maxNum = 0
        left = 0; right = len(height) - 1
        while left < right:
            maxNum = max(maxNum, (right - left) * min(height[right],height[left]))
            if height[left] < height[right]: left += 1
            else: right -= 1
        return maxNum
查看评论

[LeetCode]Container With Most Water, 解题报告

前言 难怪LeetCode OJ在找工作时被很多人推荐,发现了这道最大蓄水题目就是美团的笔试最后一道题,当时我霸笔只有着一道题目没有答出来,因此也就没有获得面试机会,可惜了 题目 Given n ...
  • zinss26914
  • zinss26914
  • 2013-12-10 19:47:10
  • 20074

[LeetCode][11]Container With Most Water解析 时间复杂度为O(n) -Java实现

Q: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate...
  • u014629433
  • u014629433
  • 2016-06-12 14:16:19
  • 1567

【LeetCode】Container With Most Water 解题报告

【题目】 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordina...
  • ljiabin
  • ljiabin
  • 2014-12-02 09:24:29
  • 12380

LeetCode --- 11. Container With Most Water

题目链接:Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents...
  • makuiyu
  • makuiyu
  • 2015-01-29 10:49:05
  • 2497

Leetcode Container With Most Water 解题报告

题目地址:http://oj.leetcode.com/problems/container-with-most-water/ 基本描述:x轴上在1,2,...,n点上有许多垂直的线段,长度依次是a1...
  • worldwindjp
  • worldwindjp
  • 2014-01-23 10:22:20
  • 3568

LeetCode 11. Container With Most Water(容器装水)

原题网址:https://leetcode.com/problems/container-with-most-water/ Given n non-negative integers a1,...
  • jmspan
  • jmspan
  • 2016-05-19 05:24:14
  • 522

LeetCode(11) ContainerWithMostWater

题目如下: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i,...
  • feliciafay
  • feliciafay
  • 2013-12-09 08:23:48
  • 3596

[LeetCode]11.Container With Most Water

【题目】 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (...
  • SunnyYoona
  • SunnyYoona
  • 2015-01-21 15:45:44
  • 1434

Leetcode||11.Container With Most Water

11. Container With Most Water Total Accepted: 101382Total Submissions: 283131Diffi...
  • Lingfu74
  • Lingfu74
  • 2016-10-29 16:20:05
  • 158

【LEETCODE】11-Container With Most Water [Python]

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai)...
  • aliceyangxi1987
  • aliceyangxi1987
  • 2016-01-07 09:03:13
  • 486
    个人资料
    持之以恒
    等级:
    访问量: 8万+
    积分: 5726
    排名: 5688