Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 551 Bytes

11. Container With Most Water.md

File metadata and controls

19 lines (18 loc) · 551 Bytes

11. Container With Most Water (Medium)

  • Two pointers
  • one from left one from right and iterate once.
class Solution:
    def maxArea(self, height: List[int]) -> int:
        left, right = 0, 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