feat(11-container-with-most-water): add py3 solution

This commit is contained in:
2022-04-05 06:20:21 +05:30
parent 1c44b21de4
commit f28be89eb3
2 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
class Solution:
def maxArea(self, height: List[int]) -> int:
left = 0
right = len(height) - 1
max_area = float("-inf")
while left < right:
if height[left] <= height[right]:
area = height[left] * (right - left)
max_area = max(max_area, area)
left += 1
else:
area = height[right] * (right - left)
max_area = max(max_area, area)
right -= 1
return max_area