11 Container With Most Water

思路:使用前后两个指针, two pointer, 每次移动指向shorter one的指针,同时记录最大值

class Solution(object):
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        s,e = 0, len(height) - 1
        areaSize = 0
        while s < e:
            d = e - s
            curSize = min(height[s], height[e]) * d
            if curSize > areaSize:
                areaSize = curSize
            if height[s] < height[e]:
                s += 1
            else:
                e -= 1
        return areaSize

results matching ""

    No results matching ""