# A C++ solution beats 99.35% solutions with explanations

• ``````class Solution {
public:
/***************************************************
*  1----->2------->3-------->4
*  ↓             ↗ ↑|
*  |-----------/---||
*            /      |
*          /        |
*  |-----/---------||
*  |   /           ↓↓
*  1------>2------->3------->4
***************************************************/
vector<RandomListNode*> tmp;            // To store original list random points and recover later
int i=0;

while(current1){
RandomListNode *newNode = new RandomListNode(current1->label);
current2->next = newNode;
newNode->random = current1->random;         // The new list random point points at the next original list random node

tmp.push_back(current1->random);            // Store the random node of current original list node
current1->random = newNode;                 // The original list random point points at the new list corresponding node

current2 = newNode;
current1 = current1->next;
}

while(current2){
if(current2->random)                            // To make the new list node random node points at the corresponding node of
// the ones in the original node
current2->random = current2->random->random;
else
current2->random = NULL;
current2 = current2->next;
}