leetcode133. 克隆图

class Solution {
public:
    unordered_map<Node*,Node*>mp;
    Node* cloneGraph(Node* node) {
        if(!node)return nullptr;
        if(mp.find(node)!=mp.end()){
            return mp[node];
        }
        Node* newNode=new Node(node->val);
        mp[node]=newNode;
        for(auto& neighbor:node->neighbors){
            newNode->neighbors.push_back(cloneGraph(neighbor));
        }
        return newNode;
    }
};