方法一
class Solution:
def maxArea(self, height: List[int]) -> int:
maxx=0
for i in range(len(height)-1):
for j in range(i+1,len(height)):
area=(j-i)*min(height[i],height[j])
maxx=max(maxx,area)
return maxx
方法二:
class Solution:
def maxArea(self, height: List[int]) -> int:
left,right=0,len(height)-1
max_area=0
while left<right:
if height[left]<=height[right]:
area=(right-left)*height[left]
left+=1
else:
area=(right-left)*height[right]
right-=1
if area>max_area:
max_area=area
return max_area