https://leetcode-cn.com/problems/copy-list-with-random-pointer/submissions/



public Node copyRandomList(Node head) {if (head == null) return null;Node cur = head;Node next = null;while (cur != null) {next = cur.next;cur.next = new Node(cur.val);cur.next.next = next;cur = next;}cur = head;while (cur != null) {next = cur.next.next;cur.next.random = cur.random == null ? null : cur.random.next;cur = next;}Node ans = head.next;cur = head;while (cur != null) {next = cur.next.next;cur.next.next = next == null ? null : next.next;cur.next = next;cur = next;}return ans;}
