MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / dfs

Function dfs

javascript/0286-walls-and-gates.js:20–32  ·  view source on GitHub ↗
(rooms, row, col)

Source from the content-addressed store, hash-verified

18};
19
20const dfs = (rooms, row, col) => {
21 const [rows, cols] = [rooms.length, rooms[0].length];
22
23 for (const [_row, _col] of getNeighbors(row, rows, col, cols)) {
24 const isPreviousDistanceGreater =
25 rooms[_row][_col] <= rooms[row][col] + 1;
26 if (isPreviousDistanceGreater) continue;
27
28 rooms[_row][_col] = rooms[row][col] + 1;
29
30 dfs(rooms, _row, _col);
31 }
32};
33
34var getNeighbors = (row, rows, col, cols) =>
35 [

Callers 1

wallsAndGatesFunction · 0.70

Calls 1

getNeighborsFunction · 0.70

Tested by

no test coverage detected