7
public Pair(int i, int j, int t) {15
final int[][] dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};17
public int orangesRotting(int[][] grid) {19
Queue<Pair> q = new LinkedList<>();20
for (int i = 0; i < grid.length; i++) {21
for (int j = 0; j < grid[0].length; j++) {22
if (grid[i][j] == 2) {23
q.offer(new Pair(i, j, 0));24
} else if (grid[i][j] == 1) {30
while (q.size() != 0) {32
ans = Math.max(ans, temp.t);34
int r = temp.i + d[0];35
int c = temp.j + d[1];37
if (r >= 0 && c >= 0 && r < grid.length && c < grid[0].length && grid[r][c] == 1) {38
q.offer(new Pair(r, c, t));44
if (count != countFresh) return -1;