-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython11.py
38 lines (29 loc) · 959 Bytes
/
python11.py
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
29
30
31
32
33
34
35
36
37
38
class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
# Optimal O(N)
left, right = 0, len(height) - 1
res = 0
while left < right:
h = (min(height[left], height[right]))
w = right - left
area = h * w
res = max(res, area)
if height[left] < height[right]:
left += 1
else:
right -= 1
return res
### Brture Force O(N^2)
'''max_area = 0
for i in range(len(height)):
for j in range(i + 1, len(height)):
h = (min(height[i], height[j]))
w = j - i
area = h * w
if area > max_area:
max_area = area
return max(area, max_area)'''