[C++] For people who want straight forward solution


#1
RandomListNode* Solution::copyRandomList(RandomListNode* head) {
// orignal node as key, new node as value
unordered_map<RandomListNode*,RandomListNode*> mp;
RandomListNode *curr = head, *clone;

//first set the node data
while(curr){
    RandomListNode *t = new RandomListNode(curr->label);
    mp[curr] = t;
    curr = curr->next;
}
// then set the next and random pointers
curr = head;
while(curr){
    clone = mp[curr];
    clone->next = mp[curr->next];
    clone->random = mp[curr->random];
    curr = curr->next;
}
return mp[head];

}


Tips for quick solution