leetcode42.Trapping Rain Water

题目描述:

class Solution:
    def trap(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        l, r, res, tmp = 0, len(height)-1, 0, 0
        while l < r:
            if height[l] < height[r]:
                lower = height[l]
                l += 1
            else:
                lower = height[r]
                r -= 1
            tmp = max(tmp, lower)
            res += tmp - lower
        return res


猜你喜欢

转载自blog.csdn.net/empire_03/article/details/80069436