您当前的位置: 首页 >  leetcode

孑渡

暂无认证

  • 2浏览

    0关注

    178博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Leetcode】中等题:盛最多水的容器

孑渡 发布时间:2022-04-15 15:34:11 ,浏览量:2

盛最多水的容器

给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。 找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 返回容器可以储存的最大水量。 说明:你不能倾斜容器。 来源:力扣(LeetCode)

AC代码
class Solution:
    def maxArea(self, height: List[int]) -> int:
        res = 0
        beg, end = 0, len(height) - 1
        while beg != end:
            temp = (end - beg) * min(height[end], height[beg])
            if res  height[end]:
                end -= 1
            else:
                beg += 1
        return res
官方代码
class Solution:
    def maxArea(self, height: List[int]) -> int:
        l, r = 0, len(height) - 1
        ans = 0
        while l             
关注
打赏
1663211900
查看更多评论
0.0418s