← 返回 meta 的题目列表BFS in Eight Directions
类型:online_judge
You are given a 2D grid containing walls (-1), empty rooms (0), and gates (a large positive integer, 2147483647). Fill each empty room with the distance to its nearest gate. You can move in eight directions from a room. Return the modified grid where rooms contain the number of steps to the nearest gate. If a room can't reach any gate, it should remain unchanged. Example input:
[[0, -1, 2147483647],
[2147483647, 2147483647, -1],
[2147483647, -1, 0]]
Output:
[[0, -1, 1],
[1, 2, -1],
[2, -1, 0]]
Example
Input
[[0, -1, 2147483647],[2147483647, 2147483647, -1],[2147483647, -1, 0]]