classSolution:deftrap(self, height):"""
:type height: List[int]
:rtype: int
"""
l = len(height)
if l < 3:
return0
ans = 0
i = 0
j = l - 1
level = 0while i < j:
if height[i] < height[j]:
level = max(height[i], level)
ans += level - height[i]
i = i + 1else:
level = max(height[j], level)
ans += level - height[j]
j = j - 1return ans