Problem Description

You are given a m x n 2D grid initialized with these three possible values.

Contact me on wechat to get Amazon、Google requent Interview questions . (wechat id : jiuzhang0607)

Examples

Example1

Input:
[[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]
Output:
[[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]

Explanation:
the 2D grid is:
INF  -1  0  INF
INF INF INF  -1
INF  -1 INF  -1
  0  -1 INF INF
the answer is:
  3  -1   0   1
  2   2   1  -1
  1  -1   2  -1
  0  -1   3   4

Example2

Input:
[[0,-1],[2147483647,2147483647]]
Output:
[[0,-1],[1,2]]

解析

類似於 994. Rotting Oranges

題目給定了一個 m by n 整數矩陣 grid,

每個 grid[r][c] 有三種值

-1: 代表是一個牆或是阻礙物

0: 代表是一個門

INF: 這邊使用 $2^{31}$ -1 代表一個空房間