We’re preparing your current view and syncing the latest data.
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. For example, given [0,1,0,2,1,0,1,3,2,1,2,1], return 6 as the total units of trapped water.
An array of non-negative integers representing the elevation map.
An integer representing the total units of trapped water.
0 <= height.length <= 3 * 10^4; 0 <= height[i] <= 10^5
Example 1
Input
[0,1,0,2,1,0,1,3,2,1,2,1]
Output
6
Explanation
Water trapped between the bars is 6 units.