2
* @param {number[][]} mat5
var updateMatrix = function (mat) {6
const rows = mat.length,11
const queue = new Queue();12
const dist = Array.from({ length: rows }, () =>13
new Array(cols).fill(Infinity)16
for (let i = 0; i < rows; i++) {17
for (let j = 0; j < cols; j++) {20
queue.enqueue([i, j]);32
while (!queue.isEmpty()) {33
const [row, col] = queue.dequeue();34
for (let i = 0; i < 4; i++) {35
const nRow = row + dirs[i][0],36
nCol = col + dirs[i][1];38
if (nRow < 0 || nCol < 0 || nRow >= rows || nCol >= cols) continue;40
if (dist[nRow][nCol] > dist[row][col] + 1) {41
dist[nRow][nCol] = dist[row][col] + 1;42
queue.enqueue([nRow, nCol]);