407. Trapping Rain Water II Hard

@problem@discussion
#Array#Breadth-First Search#Heap (Priority Queue)#Matrix



1/**
2 * [407] Trapping Rain Water II
3 *
4 * Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/trap1-3d.jpg" style="width: 361px; height: 321px;" />
8 * Input: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]
9 * Output: 4
10 * Explanation: After the rain, water is trapped between the blocks.
11 * We have two small ponds 1 and 3 units trapped.
12 * The total volume of water trapped is 4.
13 * 
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/trap2-3d.jpg" style="width: 401px; height: 321px;" />
16 * Input: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]
17 * Output: 10
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	m == heightMap.length
23 * 	n == heightMap[i].length
24 * 	1 <= m, n <= 200
25 * 	0 <= heightMap[i][j] <= 2 * 10^4
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/trapping-rain-water-ii/
31// discuss: https://leetcode.com/problems/trapping-rain-water-ii/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn trap_rain_water(height_map: Vec<Vec<i32>>) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_407() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.