feat(11-container-with-most-water): add py3 solution
This commit is contained in:
17
0011_container-with-most-water/python3/solution.py
Normal file
17
0011_container-with-most-water/python3/solution.py
Normal 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
|
||||
Reference in New Issue
Block a user