Short intuitive recursive solution


#1

unordered_map<RandomListNode*, RandomListNode*> copies;

RandomListNode* Solution::copyRandomList(RandomListNode* A) {
if(!A){return NULL;}
if(copies.find(A)==copies.end() )
{
RandomListNode* cur= new RandomListNode(A->label);
copies[A]=cur;
cur->random=copyRandomList(A->random);
cur->next=copyRandomList(A->next);
}
return copies[A];
}