双指针从头尾开始,每次移动height值更小的一个,头尾向中间移动
1 class Solution(object): 2 def maxArea(self, height): 3 """ 4 :type height: List[int] 5 :rtype: int 6 """ 7 x = 0 8 y = len(height) - 1 9 res = 0 10 while y > x: 11 res = max(res, (y - x) * min (height[x], height[y])) 12 if height[x] < height[y]: 13 x += 1 14 else: 15 y -= 1 16 return res 17 18 19