Skip to content

Instantly share code, notes, and snippets.

@willwangcc
Created July 15, 2017 00:36
Show Gist options
  • Save willwangcc/10f02434728650cc6dc04ed53ddbb752 to your computer and use it in GitHub Desktop.
Save willwangcc/10f02434728650cc6dc04ed53ddbb752 to your computer and use it in GitHub Desktop.
# Time: O(n)
# Space: O(1)
# 11. Container With Most Water
class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
l = 0
r = len(height) - 1
maxArea = 0
while l < r:
area = min(height[l], height[r]) * (r-l)
maxArea = max(maxArea, area)
if height[l] > height[r]:
r -= 1
else:
l += 1
return maxArea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment