Why doesn’t this solution work?
RandomListNode* Solution::copyRandomList(RandomListNode* A) {
RandomListNode* temp, *temp2, *newHead=NULL, *i=A;
while(i!=NULL){
RandomListNode* n = new RandomListNode(i->label);
temp2 = i->random;
RandomListNode* n2 = new RandomListNode(temp2->label);
if(newHead==NULL){
newHead=n;
}
else{
temp->next = n;
temp->random = n2;
}
temp=n;
i=i->next;
}
return newHead;
}