2
public Node copyRandomList(Node head) {4
if (head == null) return null;6
HashMap<Node, Node> map = new HashMap<>();9
Node ans = new Node(head.val);11
// temproary pointer to the ans node19
// loop to store the lookalike new nodes of the original ones20
// create the new list side by side21
while (temp != null) {22
Node x = new Node(temp.val);29
// repointing them to the start33
// will have lookup of O(1) for the random nodes;34
while (temp != null) {35
tempAns.random = map.get(temp.random);36
tempAns = tempAns.next;