Starting from both ends, O(n)


  • 0

    '''

    def maxArea(self, height):
    
        if len(height) <= 1: return 0
        if len(height) == 2: return min(height[0], height[1])
    
        left, right = 0, len(height) - 1
        new_area, max_area = 0, min(height[right], height[0]) * right
    
        while left < right:
        	if height[left] < height[right]: left += 1
       		else: right -= 1
       		new_area = min(height[left], height[right]) * abs(right - left)
       		max_area = max(new_area, max_area)
    
       	return max_area
    

    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.