Sunday, September 14, 2014

Copy List with Random Pointer

Problem

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.

Idea

  • 把每个节点复制一遍, 分别插到原节点后, 新节点的random也指向对应的新节点的random
  • 把复制的节点弄成串然后分离出来

Solution


No comments:

Post a Comment