### 解题思路
和克隆图133是一个思路,利用哈希表保存每个节点克隆出来的节点,边遍历边克隆
### 代码
class Solution {
public:
unordered_map<Node*,Node*> hm;
Node* copyRandomList(Node* head) {
if(head == NULL) return head;
Node* p = head;
Node* root = new Node(head->val);
hm[head] = root;
while(p){
if(!hm[p]) hm[p] = new Node(p->val);
if(!hm[p->next]){
if(!p->next) hm[p->next] = NULL;
else hm[p->next] = new Node(p->next->val);
}
hm[p]->next = hm[p->next];
if(!hm[p->random]){
if(!p->random) hm[p->random] = NULL;
else hm[p->random] = new Node(p->random->val);
}
hm[p]->random = hm[p->random];
p = p->next;
}
return root;
}
};