首页 > 代码库 > Copy List with Random Pointer

Copy List with Random Pointer

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. 这题 是靠http://www.cnblogs.com/zuoyuan/p/3745126.html 的写的,主要思想是在node后面插入当前node 然后 再用tmp从头开始读

tmp.next.random = tmp.random.next

最后再把链表重新拆分成两个。

技术分享


代码如下:


Copy List with Random Pointer