Created
February 21, 2022 02:02
-
-
Save ericness/ac73f9a4d7f3780f7a843c940364a6ee to your computer and use it in GitHub Desktop.
LeetCode 11 solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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