11盛水最多的容器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution:
def __init__(self):
self.max_value = 0
# def maxArea(self, height: List[int]) -> int:
# for i in range(len(height)-1):
# for j in range(i+1,len(height)):
# lengh = j-i
# high = min([height[i],height[j]])
# print(lengh*high,i,j)
# if self.max_value >= lengh*high :
# continue
# else:
# self.max_value = lengh*high
# return self.max_value
def maxArea(self, height: List[int]) -> int:
left = 0
right = len(height)-1
max_value = 0
while left < right:
min_left_right = min(height[left],height[right])
max_value_undetermined = min_left_right*(right-left)
if max_value < max_value_undetermined:
max_value = max_value_undetermined
if min_left_right == height[left]:
left += 1
else:
right -= 1
return max_value