forked from yingl/LintCodeInPython
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone_graph.py
More file actions
Latest commit
19 lines (17 loc) · 595 Bytes
/
Copy pathclone_graph.py
File metadata and controls
19 lines (17 loc) · 595 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- 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