classSolution: deftrap(self, height: List[int]) -> int: ifnot height: return0 n = len(height) left = [0] * n right = [0] * n left[0] = height[0] right[n-1] = height[n-1] for i inrange(1, n): left[i] = max(left[i-1], height[i]) for i inrange(n-2, -1, -1): right[i] = max(right[i+1], height[i]) res = 0 for i inrange(n): res += min(left[i], right[i]) - height[i] return res
if __name__ == '__main__': s = Solution() print(s.trap([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]))