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

Function buildGraph

javascript/0261-graph-valid-tree.js:24–33  ·  view source on GitHub ↗
(n, edges)

Source from the content-addressed store, hash-verified

22});
23
24var buildGraph = (n, edges) => {
25 const { graph, visited } = initGraph(n);
26
27 for (const [src, dst] of edges) {
28 graph[src].push(dst);
29 graph[dst].push(src);
30 }
31
32 return { graph, visited };
33};
34
35const dfs = (node, graph, visited) => {
36 if (visited.has(node)) return;

Callers 1

validTreeFunction · 0.70

Calls 3

initGraphFunction · 0.70
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected