Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def trap(self, height):
- """
- :type height: List[int]
- :rtype: int
- """
- if height is None or not height:
- return 0
- left = 0
- right = len(height) - 1
- cur_max_left = 0
- cur_max_right = 0
- result = 0
- while right >= left:
- if height[left] <= height[right]:
- if height[left] > cur_max_left:
- cur_max_left = height[left]
- result += max(cur_max_left - height[left], 0)
- left += 1
- else:
- if height[right] > cur_max_right:
- cur_max_right = height[right]
- result += max(cur_max_right - height[right], 0)
- right -= 1
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement