```
class Solution {
public:
RandomListNode *copyRandomList(RandomListNode *head) {
if(!head) return head;
RandomListNode* p = head;
while(p){
RandomListNode* node = new RandomListNode(p->label);
node->next = p->next;
p->next = node;
p = node->next;
}
p = head;
while(p){
if(!(p->random)){
p = p->next->next;
continue;
}
p->next->random = p->random->next;
}
p = head;
RandomListNode* copy = p->next;
RandomListNode* q;
while(p){
q = p->next;
p = q->next;
if(p) q->next = p->next;
else q->next = NULL;
}
return copy;
}
};
```