Copy List with Random Pointer
Examples
Example 1:
Input: nodes = [[7,-1],[13,0],[11,4],[10,2],[1,0]]
Output: [[7,-1],[13,0],[11,4],[10,2],[1,0]]
Example 2:
Input: nodes = [[1,1],[2,1]]
Output: [[1,1],[2,1]]
Example 1:
Input: nodes = [[7,-1],[13,0],[11,4],[10,2],[1,0]]
Output: [[7,-1],[13,0],[11,4],[10,2],[1,0]]
Example 2:
Input: nodes = [[1,1],[2,1]]
Output: [[1,1],[2,1]]
A linked list of length n is represented in this format for testing:
nodes[i] = [val, randomIndex]val is the value of the ith node.randomIndex is the index of the node pointed to by random, or -1 if random is null.Return a deep copy of the list in the same format.
The returned list must preserve both next order and random pointer structure.
0 <= nodes.length <= 1000-10^4 <= val <= 10^4randomIndex == -1 or 0 <= randomIndex < nodes.length