|
3 | 3 | import java.util.LinkedList;
|
4 | 4 | import java.util.Queue;
|
5 | 5 |
|
6 |
| -/** |
7 |
| - * 994. Rotting Oranges |
8 |
| - * |
9 |
| - * In a given grid, each cell can have one of three values: |
10 |
| - * |
11 |
| - * the value 0 representing an empty cell; |
12 |
| - * the value 1 representing a fresh orange; |
13 |
| - * the value 2 representing a rotten orange. |
14 |
| - * Every minute, any fresh orange that is adjacent (4-directionally) to a |
15 |
| - * rotten orange becomes rotten. |
16 |
| - * Return the minimum number of minutes that must elapse until no cell has a fresh orange. |
17 |
| - * If this is impossible, return -1 instead. |
18 |
| - * |
19 |
| - * Example 1: |
20 |
| - * Input: [[2,1,1],[1,1,0],[0,1,1]] |
21 |
| - * Output: 4 |
22 |
| - * |
23 |
| - * Example 2: |
24 |
| - * Input: [[2,1,1],[0,1,1],[1,0,1]] |
25 |
| - * Output: -1 |
26 |
| - * Explanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally. |
27 |
| - * |
28 |
| - * Example 3: |
29 |
| - * Input: [[0,2]] |
30 |
| - * Output: 0 |
31 |
| - * Explanation: Since there are already no fresh oranges at minute 0, the answer is just 0. |
32 |
| - * |
33 |
| - * Note: |
34 |
| - * 1 <= grid.length <= 10 |
35 |
| - * 1 <= grid[0].length <= 10 |
36 |
| - * grid[i][j] is only 0, 1, or 2. |
37 |
| - */ |
38 | 6 | public class _994 {
|
39 | 7 | public static class Solution1 {
|
40 | 8 | int[] directions = new int[]{0, 1, 0, -1, 0};
|
|
0 commit comments