You are given an R x C grid representing a city map.
grid[r][c] = 1
means there is a taxi located at cell
(r, c)
.
grid[r][c] = 0
means the cell is empty.
Return an R x C matrix dist where dist[r][c] is the length of the shortest path from cell (r, c) to any taxi.
If a cell cannot reach any taxi, set its distance to -1.
grid
: a 2D array of 0/1 integers
dist
: a 2D array of integers
1 <= R, C <= 2000
(or any size where an
O(R*C)
solution is expected)
0
taxis or many taxis.