Skip to content

Instantly share code, notes, and snippets.

@ericness
Created February 21, 2022 02:02
Show Gist options
  • Save ericness/ac73f9a4d7f3780f7a843c940364a6ee to your computer and use it in GitHub Desktop.
Save ericness/ac73f9a4d7f3780f7a843c940364a6ee to your computer and use it in GitHub Desktop.
LeetCode 11 solution
from typing import List
class Solution:
def maxArea(self, height: List[int]) -> int:
"""Calculate max area between array elements.
Args:
height (List[int]): List of heights
Returns:
int: Max area for water
"""
left = 0
right = len(height) - 1
max_area = 0
while left < right:
area = min(height[left], height[right]) * (right - left)
if area > max_area:
max_area = area
if height[left] > height[right]:
right -= 1
else:
left += 1
return max_area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment