- 思路
还是双指针法,每次将短板一端向中间移,因为长板往短板移动的话一定是越来越少,而短板向长板移动的话,虽然宽度在变短,但是可能高度会变高,结果可能会变大,(ps不得不说Python比c好用多了)
class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
i = 0
j = len(height)-1
res = 0
while i<j:
width = j-i
if height[i] < height[j]:
h = height[i]
i += 1
else:
h = height[j]
j -= 1
temp = h * width
if temp>res:
res = temp
return res