class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int """ left_temp_max = [0 for i in range(len(height))] # 每个位置的左边最高值 left_max = 0 right_max = 0 for i in range(len(height)): if height[i] > left_max: left_max = height[i] left_temp_max[i] = left_max total = 0 for i in range(len(height)-1, -1, -1): if height[i] > right_max: right_max = height[i] if min(right_max, left_temp_max[i]) > height[i]: # 主要判断 total += min(right_max, left_temp_max[i]) - height[i] return total