-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsolution.py
More file actions
17 lines (15 loc) · 481 Bytes
/
Copy pathsolution.py
File metadata and controls
17 lines (15 loc) · 481 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
# Time: O(n)
# Space: O(1)
def max_area(self, height: list[int]) -> int:
left = 0
right = len(height) - 1
max_area_so_far = 0
while left < right:
area = min(height[left], height[right]) * (right - left)
max_area_so_far = max(area, max_area_so_far)
if height[right] > height[left]:
left += 1
else:
right -= 1
return max_area_so_far