标签:
图的复制
class Solution { public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node ){ unordered_map<UndirectedGraphNode*, UndirectedGraphNode*>map; if(node == NULL) return NULL; return clone(node,map); } UndirectedGraphNode *clone(UndirectedGraphNode *node, unordered_map<UndirectedGraphNode*,UndirectedGraphNode*>&map){ if(map.find(node) != map.end()) return map[node]; UndirectedGraphNode *new_node = new UndirectedGraphNode(node->label); map[node] = new_node; for(int i = 0; i < node.neighbors.size(); i++) new_node->neighbors.push_back(clone(node->neighbors[i],map)); return new_node; } };
标签:
原文地址:http://blog.csdn.net/sina012345/article/details/42321189