WillWang-X
7/15/2017 - 12:36 AM

11. Container With Most Water.py

# Time: O(n)
# Space: O(1)
# 11. Container With Most Water


class Solution(object):
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        l = 0
        r = len(height) - 1
        maxArea = 0
        
        while l < r:
            area = min(height[l], height[r]) * (r-l)
            maxArea = max(maxArea, area)
            if height[l] > height[r]:
                r -= 1
            else:
                l += 1
        return maxArea