Skip to content

Commit cbd8b3c

Browse files
committed
[Add] 11. Container With Most Water
1 parent 43a84a5 commit cbd8b3c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Leetcode/container_most_water.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 11. Container With Most Water
2+
3+
class Solution:
4+
def maxArea(self, height: List[int]) -> int:
5+
n = len(height)
6+
left = 0
7+
right = n - 1
8+
result = 0
9+
10+
while left < right:
11+
cur_area = min(height[left], height[right]) * (right - left)
12+
result = max(result, cur_area)
13+
14+
if height[left] < height[right]: left += 1
15+
else: right -= 1
16+
17+
return result

0 commit comments

Comments
 (0)