您的位置:首页 > 其它

LintCode:装最多水的容器

2016-04-25 20:36 429 查看
LintCode:装最多水的容器

class Solution:
# @param heights: a list of integers
# @return: an integer
def maxArea(self, heights):
# write your code here
if len(heights) == 0:
return 0
max_ans = 0
min_height = heights[0]
for i in range(len(heights)):
if heights[i] >= min_height:
min_height = heights[i]
for j in range(i+1, len(heights)):
area = min(heights[i], heights[j]) * (j - i)
if area > max_ans:
max_ans = area
else:
pass
return max_ans
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: