Direction helper array
int[][] dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; while (!queue.isEmpty()) { int[] cell = queue.poll(); for (int[] d : dirs) { int r = cell[0] + d[0]; int c = cell[1] + d[1]; if (r >= 0 && r < m && c >= 0 && c < n) { queue.add(new int[] {r, c}); } } }
评论
发表评论