You are given the head of a linked list of length n where each node contains an additional pointer random, which may point to any node in the list or be null.
Construct a deep copy of the list. The deep copy must consist of exactly n new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointers of the new nodes should point to new nodes in the copied list such that the structural relationships of the original list are preserved. None of the pointers in the copied list should reference nodes in the original list.
Return the head of the copied linked list.
Constraints:
n
Node.val
Node.random is null or points to a node in the linked list.
You are given the head of a linked list of length n where each node contains an additional pointer random, which may point to any node in the list or be null.
Construct a deep copy of the list. The deep copy must consist of exactly n new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointers of the new nodes should point to new nodes in the copied list such that the structural relationships of the original list are preserved. None of the pointers in the copied list should reference nodes in the original list.
Return the head of the copied linked list.
Constraints:
n
Node.val
Node.random is null or points to a node in the linked list.