← 返回 amazon 的题目列表Rotting Oranges
类型:online_judge
Given a grid of integers where each cell can be a fresh orange, a rotten orange, or empty, return the minimum number of minutes that must elapse until no cell has a fresh orange. If it is impossible to rot all oranges, 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:
m == grid.length
n == grid[i].length
1 <= m, n <= 10
grid[i][j] is only 0, 1, or 2
Example
Input
[[2,1,1],[1,1,0],[0,1,1]]