class Solution {
public Node copyRandomList(Node head) {
if(head == null) return null;
Node cur = head;
//新建一个哈希表
Map<Node,Node> map = new HashMap<>();
while(cur != null){
map.put(cur,new Node(cur.val));
cur = cur.next;
}
cur = head;
//构建新链表的next和random指向
while(cur != null){
//进行链表的赋值操作,让当前节点的next 指向cur.next
map.get(cur).next = map.get(cur.next);
map.get(cur).random = map.get(cur.random);
cur = cur.next;
}
return map.get(head);
}
}