(int[] height)
| 1 | class Solution { |
| 2 | public int trap(int[] height) { |
| 3 | int result=0; |
| 4 | int i = 0, j = height.length - 1; |
| 5 | int left_max = 0, right_max = 0; |
| 6 | |
| 7 | while(i<=j) |
| 8 | { |
| 9 | if(height[i]<height[j]) |
| 10 | { |
| 11 | if(height[i]>left_max) left_max=height[i]; |
| 12 | else result+=left_max-height[i]; |
| 13 | i++; |
| 14 | } |
| 15 | else |
| 16 | { |
| 17 | if(height[j]>right_max) right_max=height[j]; |
| 18 | else result+=right_max-height[j]; |
| 19 | j--; |
| 20 | } |
| 21 | } |
| 22 | return result; |
| 23 | } |
| 24 | } |
nothing calls this directly
no outgoing calls
no test coverage detected