题解 | 盛水最多的容器
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param height int整型一维数组 # @return int整型 # class Solution: def maxArea(self , height: List[int]) -> int: # write code here n = len(height) if n < 2: return 0 l, r = 0, n-1 res = 0 while l < r: res = max(res, (r - l) * min(height[l], height[r])) if height[l]<height[r]: l = l+1 else: r = r - 1 return res
贪心贪心;面积等于X横坐标*Y纵坐标,X是每次移动都-1的,为了是结果’尽可能大’,那么把Y坐标比较小的移动