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

Function validTree

javascript/0261-graph-valid-tree.js:8–17  ·  view source on GitHub ↗
(n, edges, root = 0)

Source from the content-addressed store, hash-verified

6 * @return {boolean}
7 */
8var validTree = function (n, edges, root = 0) {
9 const isEqual = edges.length === n - 1;
10 if (!isEqual) return false;
11
12 const { graph, visited } = buildGraph(n, edges);
13
14 dfs(root, graph, visited);
15
16 return visited.size === n;
17};
18
19var initGraph = (n) => ({
20 graph: new Array(n).fill().map(() => []),

Callers

nothing calls this directly

Calls 5

compressFunction · 0.85
buildGraphFunction · 0.70
dfsFunction · 0.70
bfsFunction · 0.70
findFunction · 0.70

Tested by

no test coverage detected