题目
代码
class Solution {
public Node copyRandomList(Node head){
if(head == null) return null;
Map<Node,Node> map = new HashMap<>();
for(Node cur = head; cur != null; cur = cur.next){
map.put(cur,new Node(cur.val));
}
for(Node cur = head; cur != null; cur = cur.next){
map.get(cur).next = map.get(cur.next);
map.get(cur).random = map.get(cur.random);
}return map.get(head);
}
}