题解 | #复杂链表的复制#
复杂链表的复制
http://www.nowcoder.com/practice/f836b2c43afc4b35ad6adc41ec941dba
# -*- coding:utf-8 -*- # class RandomListNode: # def __init__(self, x): # self.label = x # self.next = None # self.random = None class Solution: # 返回 RandomListNode def Clone(self, pHead): if pHead==None: return None # write code here cur=pHead head=RandomListNode(0) amap={} while(cur): new_node=RandomListNode(cur.label) amap[cur]=new_node cur=cur.next cur=pHead while (cur): node=amap[cur] node.next=amap[cur.next] if cur.next else None node.random=amap[cur.random] if cur.random else None cur=cur.next return amap[pHead]