Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxArea(self, height: List[int]) -> int:
- """ How to solve it: You can have two pointers advancing from the outside in. The tricky thing is
- knowing how to decide which pointer to advance inwards. I think the key insight is to realize that any
- *better* combination that you can find by moving inwards *must* involve the *taller* of the two walls
- staying, while the *shorter* of the two walls moves inwards. The shorter wall is the limiting factor
- that limits the current water and would continue to limit any taller wall on the other side.
- """
- l = 0
- r = len(height) - 1
- max_water = 0
- while l < r:
- max_water = max(max_water, (r - l) * min(height[l], height[r]))
- if height[l] <= height[r]:
- l += 1
- else:
- r -= 1
- return max_water
Advertisement
Add Comment
Please, Sign In to add comment