Class Solution
java.lang.Object
g0001_0100.s0042_trapping_rain_water.Solution
42 - Trapping Rain Water.<p>Hard</p>
<p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" alt="" /></p>
<p><strong>Input:</strong> height = [0,1,0,2,1,0,1,3,2,1,2,1]</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> height = [4,2,0,3,2,5]</p>
<p><strong>Output:</strong> 9</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == height.length</code></li>
<li><code>1 <= n <= 2 * 10<sup>4</sup></code></li>
<li><code>0 <= height[i] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
trap
public int trap(int[] height)
-