Last active
February 7, 2022 05:55
-
-
Save amarjitdhillon/ecf0a48c05fa3499653ef3c4f921b72f to your computer and use it in GitHub Desktop.
Container With Most Water
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
class Solution: | |
def maxArea(self, height: List[int]) -> int: | |
maxArea, currArea, l, r = 0,0, 0, len(height)-1 | |
while(l < r and l >= 0 and r <= len(height)-1): | |
currArea = min(height[l],height[r]) * (r-l) | |
if currArea > maxArea: | |
maxArea = currArea # udpate the max area | |
if height[l] < height[r]: # left pointer needs to be incremented | |
l += 1 | |
else: # both cases of height[l] > height[r] and height[l] == height[r] | |
r -= 1 | |
return maxArea | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment