Skip to content

Instantly share code, notes, and snippets.

@ThomasHigginson
Created March 30, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasHigginson/b6b9ba9cc885321e171e535a2aa86b82 to your computer and use it in GitHub Desktop.
Save ThomasHigginson/b6b9ba9cc885321e171e535a2aa86b82 to your computer and use it in GitHub Desktop.
def maxArea(self, height: List[int]) -> int:
i = 0
j = len(height) - 1
maxArea = -inf
currMax = -inf
while i < j:
currMax = min(height[i], height[j]) * (j - i)
maxArea = max(currMax, maxArea)
if height[i] < height[j]:
currIdx = i
while i < j and height[currIdx] >= height[i]:
i += 1
else:
currIdx = j
while i < j and height[currIdx] >= height[j]:
j -= 1
return maxArea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment