今日学习内容
3DGS
力扣每日一题
3D接雨水
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| class Solution { private static final int[][] DIRS = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
public int trapRainWater(int[][] heightMap) { int m = heightMap.length, n = heightMap[0].length; PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> (a[0] - b[0])); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (i == 0 || i == m - 1 || j == 0 || j == n - 1) { pq.add(new int[]{heightMap[i][j], i, j}); heightMap[i][j] = -1; } } }
int ans = 0; while (!pq.isEmpty()) { int[] t = pq.poll(); int minHeight = t[0], i = t[1], j = t[2]; for (int[] d : DIRS) { int x = i + d[0], y = j + d[1]; if (0 <= x && x < m && 0 <= y && y < n && heightMap[x][y] >= 0) { ans += Math.max(minHeight - heightMap[x][y], 0); pq.add(new int[]{Math.max(minHeight, heightMap[x][y]), x, y}); heightMap[x][y] = -1; } } } return ans; } }
|
Java复习进度
Java进阶之路
集合篇框架写完了.
Java SE
56/56
Java集合框架
30/30
Java并发编程
14 -> 16 /71
JVM
MySQL
55/83
Redis
14/57
Spring
0/41
操作系统
计算机网络
MyBatis
RocketMQ
分布式
微服务
设计模式
Linux
算法
三道题目.
简历制作
项目-TecHub
项目-派聪明
生活篇