1def copyRandomList(head):2    if not head:3        return None4    curr = head5    while curr:6        copy = Node(curr.val)7        curr.next, copy.next = copy, curr.next8        curr = copy.next9    curr = head10    while curr:11        if curr.random:12            curr.next.random = curr.random.next13        curr = curr.next.next14    curr = head15    copy_head = head.next16    while curr:17        copy = curr.next18        curr.next = copy.next19        copy.next = copy.next.next if copy.next else None20        curr = curr.next21    return copy_head