- Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathclone-graph.py
More file actions
Latest commit
21 lines (18 loc) · 646 Bytes
/
Copy pathclone-graph.py
File metadata and controls
21 lines (18 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# coding: utf-8
classSolution:
# @param node, a undirected graph node
# @return a undirected graph node
def__init__(self):
self.dict= {} # 存放已复制的节点
defcloneGraph(self, node):
ifnotnode:
returnNone
# write your code here
ifnodeinself.dict:
returnself.dict[node] # 该节点已复制
ret=UndirectedGraphNode(node.label)
self.dict[node] =ret
forneighborinnode.neighbors:
ret.neighbors.append(self.cloneGraph(neighbor))
returnret
# medium: http://lintcode.com/zh-cn/problem/clone-graph/