Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def trap(self, height: List[int]) -> int:
- if(len(height) == 0):
- return 0
- maxi = max(height)
- maxl = height.index(maxi)
- maxr = len(height) - height[::-1].index(maxi) - 1
- h = [0]*len(height)
- h[0] = height[0]
- h[-1] = height[-1]
- for i in range(1,maxr+1):
- if(h[i-1] <= height[i]):
- h[i] = height[i]
- else:
- h[i] = h[i-1]
- for i in range(maxr,len(height)-1).__reversed__():
- if(h[i+1] <= height[i]):
- h[i] = height[i]
- else:
- h[i] = h[i+1]
- return sum(h) - sum(height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement