盛最多水的容器

作者: 不爱去冒险的少年y | 来源:发表于2018-05-14 11:05 被阅读11次

盛最多水的容器

给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i,ai) 。画 n 条垂直线,使得垂直线 i的两个端点分别为 (i,ai) 和 (i, 0)。找出其中的两条线,使得它们与x轴共同构成的容器可以容纳最多的水。

注意:你不能倾斜容器,n 至少是2。

class Solution:

    def maxArea(self, height):

        """

        :type height: List[int]

        :rtype: int

        """

        lenght = len(height)

        sum = 0

        begin = 0

        end = lenght-1

        while True:

            if begin == end:

                break

            else:

                if height[begin]<height[end]:

                    sum = max(sum, height[begin]*(end-begin))

                    begin+=1

                else:

                    sum = max(sum, height[end]*(end-begin))

                    end-=1

        return sum

相关文章

  • 盛最多水的容器

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直...

  • 盛最多水的容器

    盛最多水的容器 给定n个非负整数a1,a2,...,an,每个数代表坐标中的一个点(i,ai) 。画n条垂直线,使...

  • 盛最多水的容器

    题目来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/cont...

  • 盛最多水的容器

    题目描述 思路 题解代码

  • 盛最多水的容器

    盛最多水的容器 难度中等1826 收藏 分享 切换为英文 关注 反馈 给你 n 个非负整数 a1,a2,...,a...

  • 盛最多水的容器

    题目描述:  给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内...

  • 盛最多水的容器

    给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直...

  • 盛最多水的容器

    题目 https://leetcode-cn.com/problems/container-with-most-w...

  • 盛最多水的容器

    题目: 题目的理解: 计算两个数之间的面积,获取到最大的面积。 时间复杂度为O(n!), 当数量越大计算时间越长,...

  • 盛最多水的容器

    LeetCode第十一题 题目描述:给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i...

网友评论

    本文标题:盛最多水的容器

    本文链接:https://www.haomeiwen.com/subject/ujyddftx.html