class Solution {
public Node copyRandomList(Node head) {
if (head == null) {
return head;
}
Node cur = head;
while(cur != null){
Node copy = new Node(cur.val);
copy.next = cur.next;
cur.next = copy;
cur = cur.next.next;
}
Node cur2 = head;
while(cur2 != null){
if (cur2.random != null) cur2.next.random = cur2.random.next;
cur2 = cur2.next.next;
}
Node cur3 = head, dummy = head.next;
while(cur3 != null && cur3.next != null){
Node temp = cur3.next;
cur3.next = temp.next;
cur3 = temp;
}
return dummy;
}
}