首页 > 其他 > 详细

11. 盛最多水的容器

时间:2019-01-19 17:06:53      阅读:200      评论:0      收藏:0      [点我收藏+]

11. 盛最多水的容器

方法一

class Solution(object):
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        h_len = len(height)
        i = 0
        k = -1
        s = []
        while h_len + k - i >= 1:
            s.append(min(height[i], height[k]) * (h_len + k - i))
            if height[i] <= height[k]:
                i += 1
            else:
                k -= 1
        return max(s)

# 测试用例
"""
输入: [1,8,6,2,5,4,8,3,7]
输出: 49
"""

 

11. 盛最多水的容器

原文:https://www.cnblogs.com/xiao-xue-di/p/10292153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!