Skip to content

Commit dfbdbe2

Browse files
authored
Merge pull request #2415 from SamiiC/main
Update 0011-container-with-most-water.py
2 parents 29f66f4 + 3bc43fe commit dfbdbe2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

python/0011-container-with-most-water.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ class Solution:
22
def maxArea(self, height: List[int]) -> int:
33
l, r = 0, len(height) - 1
44
res = 0
5+
h = max(height)
56

67
while l < r:
78
res = max(res, min(height[l], height[r]) * (r - l))
89
if height[l] < height[r]:
910
l += 1
1011
elif height[r] <= height[l]:
1112
r -= 1
13+
14+
if (r-l) * h <= res:
15+
break
1216
return res

0 commit comments

Comments
 (0)