、
class Solution {
public Node copyRandomList(Node head) {
HashMap<Node,Node> hm = new HashMap();
Node cur = head;
//将新复制的链表放在map的value,方便找到与原节点对应的节点
while(cur != null){
hm.put(cur,new Node(cur.val));
cur = cur.next;
}
cur = head;
//复制分治结构,可以通过常数时间的复杂度来找到对应节点
while(cur != null){
hm.get(cur).next = hm.get(cur.next);
hm.get(cur).random = hm.get(cur.random);
cur = cur.next;
}
return hm.get(head);
}
}