LeetCode #11: Container With Most Water
β’ 58 words β’ 1 min β’ updated
LeetCode #11: Container With Most Water:
Two pointers inwards:
python
class Solution:
def maxArea(self, height: List[int]) -> int:
ans = 0
left = 0
right = len(height) - 1
while left < right:
area = (right - left) * min(height[left], height[right])
ans = max(ans, area)
if height[left] < height[right]:
left += 1
else:
right -= 1
return ans