Skip to content

Commit 45db5b3

Browse files
update 994
1 parent ee74fa9 commit 45db5b3

File tree

1 file changed

+4
-6
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-6
lines changed

Diff for: src/main/java/com/fishercoder/solutions/_994.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ public int orangesRotting(int[][] grid) {
6767
}
6868
}
6969
}
70-
int min = 0;
70+
int time = 0;
7171
int[] directions = new int[]{0, 1, 0, -1, 0};
7272
while (!queue.isEmpty() && !fresh.isEmpty()) {
7373
int size = queue.size();
74-
if (size > 0) {
75-
min++;
76-
}
74+
time++;
7775
for (int i = 0; i < size; i++) {
7876
int[] curr = queue.poll();
7977
for (int k = 0; k < directions.length - 1; k++) {
@@ -82,15 +80,15 @@ public int orangesRotting(int[][] grid) {
8280
if (nextX >= 0 && nextX < m && nextY >= 0 && nextY < n && grid[nextX][nextY] == 1) {
8381
fresh.remove(nextX * n + nextY);
8482
if (fresh.isEmpty()) {
85-
return min;
83+
return time;
8684
}
8785
grid[nextX][nextY] = 2;
8886
queue.offer(new int[]{nextX, nextY});
8987
}
9088
}
9189
}
9290
}
93-
return fresh.isEmpty() ? min : -1;
91+
return fresh.isEmpty() ? time : -1;
9492
}
9593
}
9694

0 commit comments

Comments
 (0)