11. Container With Most Water
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 58% Topics: Array, Two Pointers, Greedy
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
# @return an integer
def maxArea(self, height):
max_area, i, j = 0, 0, len(height) - 1
while i < j:
max_area = max(max_area, min(height[i], height[j]) * (j - i))
if height[i] < height[j]:
i += 1
else:
j -= 1
return max_area
Solution from kamyu104/LeetCode-Solutions · MIT