package leetcode;

/**
 * https://leetcode.com/problems/trapping-rain-water-ii/
 */
public class Problem407 {
    public int trapRainWater(int[][] heightMap) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem407 prob = new Problem407();
        System.out.println(prob.trapRainWater(new int[][]{
            {1, 4, 3, 1, 3, 2},
            {3, 2, 1, 3, 2, 4},
            {2, 3, 3, 2, 3, 1}
        })); // 4
    }
}

@@ -12,16 +12,49 @@
 tcode;%0A%0A
+import java.util.PriorityQueue;%0A%0A
 /**%0A * h
@@ -182,24 +182,892 @@
 eightMap) %7B%0A
+        // https://www.youtube.com/watch?v=cJayBq38VYw%0A        PriorityQueue%3CRowCol%3E queue = new PriorityQueue%3C%3E((a, b) -%3E Integer.compare(a.value, b.value));%0A        // top%0A        for (int col = 0; col %3C heightMap%5B0%5D.length; col++) %7B%0A            queue.add(new RowCol(0, col, heightMap%5B0%5D%5Bcol%5D));%0A        %7D%0A        // left%0A        for (int row = 1; row %3C heightMap.length - 1; row++) %7B%0A            queue.add(new RowCol(row, 0, heightMap%5Brow%5D%5B0%5D));%0A        %7D%0A        // bottom%0A        for (int col = 0; col %3C heightMap%5BheightMap.length - 1%5D.length; col++) %7B%0A            queue.add(new RowCol(heightMap.length - 1, col, heightMap%5BheightMap.length - 1%5D%5Bcol%5D));%0A        %7D%0A        // right%0A        for (int row = 1; row %3C heightMap.length - 1; row++) %7B%0A            queue.add(new RowCol(row, heightMap%5Brow%5D.length - 1, heightMap%5Brow%5D%5BheightMap%5Brow%5D.length - 1%5D));%0A        %7D%0A
         // T
@@ -1069,16 +1069,17 @@
  // TODO
+:
 %0A       
@@ -1096,16 +1096,304 @@
 %0A    %7D%0A%0A
+    private static class RowCol %7B%0A        private final int row;%0A        private final int col;%0A        private final int value;%0A%0A        public RowCol(int row, int col, int value) %7B%0A            this.row = row;%0A            this.col = col;%0A            this.value = value;%0A        %7D%0A    %7D%0A%0A
     publ
@@ -1581,23 +1581,20 @@
    %7B
-3, 
 2, 
-1
+3
 , 3, 2, 
 4%7D,%0A
@@ -1589,17 +1589,20 @@
 , 3, 2, 
-4
+3, 1
 %7D,%0A     

Update problem 407