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
【剑指offer】面试题26:复杂链表的复制
最新推荐文章于 2024-06-02 16:06:30 发布