-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42.py
More file actions
31 lines (25 loc) · 722 Bytes
/
Copy path42.py
File metadata and controls
31 lines (25 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution(object):
def trap(self, height):
"""
:type height: List[int]
:rtype: int
"""
left = []
right = []
maxleft = 0
maxright = 0
for i in range(len(height)):
left.append(maxleft)
maxleft=max(maxleft, height[i])
right.append(maxright)
maxright=max(maxright, height[len(height)-1-i])
right.reverse()
ret = 0
for i in range(len(height)):
h = min(left[i], right[i])
if h>height[i]:
ret += h-height[i]
return ret
if __name__ == '__main__':
solution = Solution()
print solution.trap([0,1,0,2,1,0,1,3,2,1,2,1])