Trapping Rain Water
Unit-width columns have the supplied nonnegative heights. Return the total area of rainwater retained between columns.
Example 1
height = [4,1,2,0,3]6Explanation
Trapped depths at indices 1,2,3 are 2,1,3, totaling 6.
Example 2
height = [1,2,3]0Explanation
An increasing skyline has no lower column bounded on both sides.
Example 3
height = [2,0,2]2Explanation
The height-two walls enclose two units above the central zero.
Constraints
- 0 <= len(height) <= 20000
- Heights are 0..100000
Function contract
trapArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[4,1,2,0,3]