Open fockspaces opened 1 year ago
greedy + two pointers: determine the searching direction, update ans in each iteration.
class Solution:
def maxArea(self, height: List[int]) -> int:
l, r = 0, len(height) - 1
ans = 0
while l < r:
amount = (r - l) * min(height[l], height[r])
ans = max(ans, amount)
if height[l] < height[r]:
l += 1
else:
r -= 1
return ans