Solution using unordered_map C++


#1
RandomListNode* Solution::copyRandomList(RandomListNode* A) {
unordered_map<RandomListNode *, RandomListNode *> m;
auto it = A;
while(it){
    m[it] = new RandomListNode(it->label);
    it = it->next;
}

auto d = new RandomListNode(-1);
auto head = d;
while(A){
    d->next = m[A];
    d = d->next;
    d->random = m[A->random];
    A = A->next;
}
return head->next;

}