给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。
要求返回这个链表的 深拷贝。 
我们用一个由 n 个节点组成的链表来表示输入/输出中的链表。每个节点用一个 [val, random_index] 表示:
val:一个表示Node.val的整数。random_index:随机指针指向的节点索引(范围从0到n-1);如果不指向任何节点,则为null。
示例 1:![[138]复制带随机指针的链表 - 图1](/uploads/projects/instellar@ab8afo/4b4f0af0346d3c4ba075aca4ad756ba6.png)
输入:head = [[7,null],[13,0],[11,4],[10,2],[1,0]]输出:[[7,null],[13,0],[11,4],[10,2],[1,0]]
示例 2:
![[138]复制带随机指针的链表 - 图2](/uploads/projects/instellar@ab8afo/cf2e3074b4355b833e4bb767f24c1949.png)
输入:head = [[1,1],[2,1]] 输出:[[1,1],[2,1]]示例 3:
![[138]复制带随机指针的链表 - 图3](/uploads/projects/instellar@ab8afo/9a857cbab3f01500b63e18dec1be71f1.png)
输入:head = [[3,null],[3,0],[3,null]] 输出:[[3,null],[3,0],[3,null]]示例 4:
输入:head = [] 输出:[] 解释:给定的链表为空(空指针),因此返回 null。
提示:-10000 <= Node.val <= 10000Node.random为空(null)或指向链表中的节点。- 节点数目不超过 1000 。
 
/*
// Definition for a Node.
class Node {
public:
    int val;
    Node* next;
    Node* random;
    Node(int _val) {
        val = _val;
        next = NULL;
        random = NULL;
    }
};
*/
class Solution {
public:
    Node* copyRandomList(Node* head) {
        if (head == nullptr)
            return head;
        //遍历原链表 创建新链表节点并建立映射关系
        unordered_map<Node*, Node*> map; //<原链表节点,对应位置的新链表节点>
        Node* cur = head;
        while (cur)
        {
            map[cur] = new Node(cur->val);
            cur = cur->next;
        }
        //遍历原链表 根据map链接新链表
        cur = head;
        while (cur)
        {
            Node* node = map[cur];
            node->next = map[cur->next];
            node->random = map[cur->random];
            cur = cur->next;
        }
        return map[head];
    }
};
                    