| 83 | |
| 84 | """ |
| 85 | class Solution(object): |
| 86 | def trap(self, height): |
| 87 | """ |
| 88 | :type height: List[int] |
| 89 | :rtype: int |
| 90 | """ |
| 91 | stack = [0] |
| 92 | |
| 93 | i = 1 |
| 94 | length = len(height) |
| 95 | result = [0] * length |
| 96 | |
| 97 | while i < length: |
| 98 | if height[i] <= height[stack[-1]]: |
| 99 | stack.append(i) |
| 100 | i += 1 |
| 101 | else: |
| 102 | mins = min(height[stack[0]], height[i]) |
| 103 | index = 0 |
| 104 | for j in xrange(stack[0], i): |
| 105 | _ = mins - height[j] |
| 106 | |
| 107 | if _ > 0 and _ > result[j]: |
| 108 | result[j] = _ |
| 109 | |
| 110 | if height[stack[0]] <= height[i]: |
| 111 | stack = [] |
| 112 | else: |
| 113 | stack = [stack[0]] |
| 114 | |
| 115 | stack.append(i) |
| 116 | i += 1 |
| 117 | |
| 118 | return sum(result) |
| 119 |
nothing calls this directly
no outgoing calls
no test coverage detected