← 返回 amazon 的题目列表Rotting Oranges: Minimum Time to Rot All Fresh Oranges
类型:online_judge
amazon
Rotting Oranges
Given a m x n grid, each cell can have one of three values:
Value 0 representing an empty cell;
Value 1 representing a fresh orange;
Value 2 representing a rotten orange.
Every minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten.
Return the minimum number of minutes that must elapse until no cell has a fresh orange. If it is impossible to rot every orange, return -1.
Example:
Input:
[[2,1,1],[1,1,0],[0,1,1]]
Output:
4
Input:
[[2,1,1],[0,1,1],[1,0,1]]
Output:
-1
Input:
[[0,2]]
Output:
0
Constraints:
1 <= m, n <= 10
Example
Input
[[2,1,1],[1,1,0],[0,1,1]]