Description
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
Example 1:
1 | Input: |
Note:
- You must return the copy of the given head as a reference to the cloned list.
解法
主要是random指针的处理,这里利用hashmap实现对random的复制,即hashmap存储新老节点的对应关系
具体代码如下:
1 | class Solution { |