/*
struct RandomListNode {
    int label;
    struct RandomListNode *next, *random;
    RandomListNode(int x) :
            label(x), next(NULL), random(NULL) {
    }
};
*/
class Solution {
public:
    unordered_map<RandomListNode*, RandomListNode*>hash;
    RandomListNode* Clone(RandomListNode* pHead) {
        if (!pHead) {
            return nullptr;
        }
        if (hash.count(pHead)) {
            return hash[pHead];
        }
        RandomListNode *node = new RandomListNode(pHead->label);
        hash[pHead] = node;
        node->next = Clone(pHead->next);
        node->random = Clone(pHead->random);
        return node;
        
    }
};