【剑指offer】复杂链表的复制(python)
递归终止条件。if pHead is None: return
# -*- 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):
# write code here
if pHead is None:
return None
cloneHead = RandomListNode(pHead.label)
cloneHead.random = pHead.random
cloneHead.next = self.Clone(pHead.next)
return cloneHead
京公网安备 11010502036488号