Java Clean Code
\nclass Solution {\n    public int trapRainWater(int[][] heightMap) {\n        Queue<int[]> pq = new PriorityQueue<>((a, b)->(a[2] - b[2]));\n        int n = he
```\nclass Solution {\n    public int trapRainWater(int[][] heightMap) {\n        Queue<int[]> pq = new PriorityQueue<>((a, b)->(a[2] - b[2]));\n        int n = heightMap.length;\n        if (n < 2) {\n            return 0;\n        }\n        int m = heightMap[0].length;\n        if (m < 2) {\n            return 0;\n        }\n        int[] dx = {1, -1, 0, 0};\n        int[] dy = {0, 0, -1, 1};\n        boolean[][] visited = new boolean[n][m];\n        for (int i = 0; i < n; i++) {\n            visited[i][0] = true;\n            visited[i][m - 1] = true; \n            pq.add(new int[]{i, 0, heightMap[i][0]});\n            pq.add(new int[]{i, m - 1, heightMap[i][m - 1]});\n        }\n        for (int j = 0; j < m; j++) {\n            visited[0][j] = true;\n            visited[n - 1][j] = true; \n            pq.add(new int[]{0, j, heightMap[0][j]});\n            pq.add(new int[]{n - 1, j, heightMap[n - 1][j]});\n        }\n        int sum = 0;\n        while (!pq.isEmpty()) {\n            int[] temp = pq.poll();\n            for (int i = 0; i < 4; i++) {\n                int nx = temp[0] + dx[i];\n                int ny = temp[1] + dy[i];\n                if (nx < 0 || ny < 0 || nx >= n || ny >= m || visited[nx][ny]) {\n                    continue;\n                }\n                if (heightMap[nx][ny] < temp[2]) {\n                    sum += temp[2] - heightMap[nx][ny];\n                }\n                visited[nx][ny] = true;\n                pq.add(new int[]{nx, ny, Math.max(temp[2], heightMap[nx][ny])});\n            }\n        }\n        return sum;\n    }\n}\n```
[]