Skip to content

Commit bb51126

Browse files
refactor 407
1 parent 840723e commit bb51126

File tree

1 file changed

+4
-26
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-26
lines changed

src/main/java/com/fishercoder/solutions/_407.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,11 @@
22

33
import java.util.PriorityQueue;
44

5-
/**
6-
* 407. Trapping Rain Water II
7-
*
8-
* Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining.
9-
10-
Note:
11-
Both m and n are less than 110. The height of each unit cell is greater than 0 and is less than 20,000.
12-
13-
Example:
14-
15-
Given the following 3x6 height map:
16-
[
17-
[1,4,3,1,3,2],
18-
[3,2,1,3,2,4],
19-
[2,3,3,2,3,1]
20-
]
21-
22-
Return 4.
23-
24-
The above image represents the elevation map [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] before the rain.
25-
26-
After the rain, water are trapped between the blocks. The total volume of water trapped is 4.
27-
28-
*/
295
public class _407 {
306
public static class Solution1 {
31-
/** Reference: https://discuss.leetcode.com/topic/60418/java-solution-using-priorityqueue */
7+
/**
8+
* Reference: https://discuss.leetcode.com/topic/60418/java-solution-using-priorityqueue
9+
*/
3210
public class Cell {
3311
int row;
3412
int col;
@@ -70,7 +48,7 @@ public int trapRainWater(int[][] heights) {
7048
// from the borders, pick the shortest cell visited and check its neighbors:
7149
// if the neighbor is shorter, collect the water it can trap and update its height as its height plus the water trapped
7250
// add all its neighbors to the queue.
73-
int[][] dirs = new int[][] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
51+
int[][] dirs = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
7452
int res = 0;
7553
while (!queue.isEmpty()) {
7654
Cell cell = queue.poll();

0 commit comments

Comments
 (0)