class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
if len(height) == 1 or not height:
return 0
l,h = 0,len(height)-1
area = (h - l) * (height[l] if height[l] < height[h] else height[h])
while l < h:
if height[l] < height[h]:
area = area if area > height[l] * (h-l) else height[l] * (h-l)
l += 1
else:
area = area if area > height[h] * (h-l) else height[h] * (h-l)
h -= 1
return area
11. 盛最多水的容器
最新推荐文章于 2025-04-16 10:36:41 发布