2014年2月6日

LeetCode: 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.我想到了一个时间O(n),空间O(n)的算法。关键要注意的地方是,头节点一定不要忘了放入hashmap中,最后一个节点的next赋值为null。Method 1 (Uses O(n) extra space)This method stores the next and ar 阅读全文

posted @ 2014-02-06 13:20 longhorn 阅读(160) 评论(0) 推荐(0) 编辑

导航