LeetCode #133 Clone Graph (拷贝图)

题目:

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors

 

分析:

拷贝一个图。每个节点中用List存储它的邻居节点。

基本思路就是遍历原图,使用一个map来记录已经访问过的节点以及它和新节点的对应关系。

遍历可以考虑DFS或者BFS。下面的代码是使用BSF实现的。

Continue reading LeetCode #133 Clone Graph (拷贝图)