class Solution {
public:
RandomListNode* Clone(RandomListNode* pHead)
{
map<RandomListNode*, RandomListNode*> aux;
RandomListNode* cur = new RandomListNode(pHead->label);
RandomListNode* head = cur;
RandomListNode* tem = pHead;
while (tem) {
tem = tem->next;
if (tem) {
RandomListNode* next = new RandomListNode(tem->label);
aux.insert({ tem,next });
cur->next = next;
cur = cur->next;
}
}
tem = head;
while (tem) {
tem->random = aux[pHead->random];
tem = tem->next;
pHead = pHead->next;
}
return head;
}
};