Copy List with Random Pointer

A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list or null. Construct a deep copy of the list. Return the head of the copied linked list. Example: Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]] Output: [[7,null],[13,0],[11,4],[10,2],[1,0]] Explanation: The new list is a copy of the original, with identical random pointers. Pattern focus: Hash Map for Deep Copy.

Input Format

head = RandomListNode

Output Format

return RandomListNode

Constraints

  • 0 <= n <= 1000
  • -10^4 <= Node.val <= 10^4

Examples

Example 1:

Input:

head = [1,2,3]

Output:

[1,2,3]
Loading...
Copy List with Random Pointer - Linked List