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

来源:互联网 发布:linux镜像iso文件下载 编辑:程序博客网 时间:2024/05/19 12:17
 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

0 0
原创粉丝点击