Skip to content

Commit

Permalink
Update 0011-container-with-most-water.py
Browse files Browse the repository at this point in the history
Clear optimized solution
  • Loading branch information
SamiiC authored Apr 14, 2023
1 parent 3433f21 commit 3bc43fe
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/0011-container-with-most-water.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ class Solution:
def maxArea(self, height: List[int]) -> int:
l, r = 0, len(height) - 1
res = 0
h = max(height)

while l < r:
res = max(res, min(height[l], height[r]) * (r - l))
if height[l] < height[r]:
l += 1
elif height[r] <= height[l]:
r -= 1

if (r-l) * h <= res:
break
return res

0 comments on commit 3bc43fe

Please sign in to comment.