classSolution: deftrap(self, height: List[int]) -> int: maxleft = [0]*len(height) maxright = [0]*len(height) for i inrange(0,len(height)): if i == 0: maxleft[i] = 0 else: maxleft[i] = max(maxleft[i-1],height[i-1]) now = len(height) - i - 1 if now == len(height) - 1: maxright[now] = 0 else: maxright[now] = max(maxright[now+1],height[now+1]) ans = 0 for i inrange(1,len(height) - 1): temp = min(maxleft[i],maxright[i]) if temp > height[i]: ans += temp - height[i] return ans