zoukankan      html  css  js  c++  java
  • 剑指Offer 35 复杂链表的复制

    复杂链表的复制

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

     1 # -*- coding:utf-8 -*-
     2 # class RandomListNode:
     3 #     def __init__(self, x):
     4 #         self.label = x
     5 #         self.next = None
     6 #         self.random = None
     7 class Solution:
     8     # 返回 RandomListNode
     9     def Clone(self, pHead):
    10         if pHead == None:
    11             return None
    12         dHead = pHead
    13         while dHead:
    14             n = RandomListNode(dHead.label)
    15             n.next = dHead.next
    16             dHead.next = n
    17             dHead = n.next
    18         dHead = pHead
    19         while dHead:
    20             dHead.next.random = dHead.random
    21             dHead = dHead.next.next
    22         
    23         dHead = pHead
    24         copyhead = RandomListNode(0)
    25         copyhead.next = pHead.next
    26         firstOne = True
    27         while dHead:
    28             copy = dHead.next
    29             dHead.next = dHead.next.next
    30             if copy.next != None:
    31                 copy.next = copy.next.next
    32             else:
    33                 copy.next = None
    34             dHead = dHead.next
    35         return copyhead.next
    36         # write code here
  • 相关阅读:
    tone() 和 IRremote 冲突的解决办法
    Github
    bit Buffer
    转载:AAC文件解析及解码
    Z变换
    FFT
    DFT
    傅里叶变换
    傅里叶变换--虚部的理解
    转载:WAV header
  • 原文地址:https://www.cnblogs.com/asenyang/p/11020658.html
Copyright © 2011-2022 走看看