MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / cloneGraph

Function cloneGraph

133-clone-graph/clone-graph.js:15–34  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

13 * @return {Node}
14 */
15var cloneGraph = function(node) {
16 if (!node) return null;
17
18 const visited = new Map();
19
20 function dfs(original) {
21 if (visited.has(original)) return visited.get(original);
22
23 const clone = new Node(original.val);
24 visited.set(original, clone);
25
26 for (let neighbor of original.neighbors) {
27 clone.neighbors.push(dfs(neighbor));
28 }
29
30 return clone;
31 }
32
33 return dfs(node);
34};

Callers

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected