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

 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

版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted @ 2015-07-02 21:28  hrhguanli  阅读(158)  评论(0编辑  收藏  举报