剑指offer 复杂链表的复制 python

版权声明:本文为博主原创文章,需转载可以私信我,同意后即可 https://blog.csdn.net/Sun_White_Boy/article/details/83245355

题目描述

输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)

样例


想法一:
分析下题目,很容易想到可以用递归来做.

class Solution:
    # 返回 RandomListNode
    def Clone(self, pHead):
        if not pHead:
            return
        newnode = RandomListNode(pHead.label)
        newnode.random = pHead.random
        newnode.next = self.Clone(pHead.next)
        return newnode

最后

刷过的LeetCode或剑指offer源码放在Github上了,希望喜欢或者觉得有用的朋友点个star或者follow。
有任何问题可以在下面评论或者通过私信或联系方式找我。
联系方式
QQ:791034063
Wechat:liuyuhang791034063
CSDN:https://blog.csdn.net/Sun_White_Boy
Github:https://github.com/liuyuhang791034063

猜你喜欢

转载自blog.csdn.net/Sun_White_Boy/article/details/83245355