MCPcopy
hub / github.com/qiyuangong/leetcode / cloneGraph

Method cloneGraph

python/133_Clone_Graph.py:29–47  ·  view source on GitHub ↗
(self, node)

Source from the content-addressed store, hash-verified

27 # return res
28
29 def cloneGraph(self, node):
30 # BFS
31 if node is None:
32 return None
33 label_map = {}
34 queue = [node]
35 graphCopy = UndirectedGraphNode(node.label)
36 label_map[node.label] = graphCopy
37 while len(queue) > 0:
38 curr = queue.pop(0)
39 for ne in curr.neighbors:
40 if ne.label in label_map:
41 label_map[curr.label].neighbors.append(label_map[ne.label])
42 else:
43 neighborCopy = UndirectedGraphNode(ne.label)
44 label_map[curr.label].neighbors.append(neighborCopy)
45 label_map[ne.label] = neighborCopy
46 queue.append(ne)
47 return graphCopy
48

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected