您的位置:首页 > 职场人生

【剑指offer】面试题26:复杂链表的复制

2014-07-16 13:32 232 查看
def copyRandomList(self, head):
if None == head: return None
phead = head
while phead:
pnext = phead.next
phead.next = RandomListNode(phead.label)
phead.next.next = pnext
phead = pnext

phead = head
while phead:
if phead.random:
phead.next.random = phead.random.next
phead = phead.next.next

head2 = RandomListNode(-1)
tail2 = head2
phead = head
while phead:
tail2.next = phead.next
phead.next = phead.next.next
phead = phead.next
tail2 = tail2.next
return head2.next
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: