-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay3
More file actions
22 lines (18 loc) · 651 Bytes
/
Day3
File metadata and controls
22 lines (18 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
##11.Container with the most water
class Solution:
def maxArea(self, height: List[int]) -> int:
left = 0
right = len(height) - 1
max_water = 0
while left < right:
# Calculate the area between the two lines
width = right - left
h = min(height[left], height[right])
area = width * h
max_water = max(max_water, area)
# Move the pointer pointing to the shorter line
if height[left] < height[right]:
left += 1
else:
right -= 1
return max_water