1、复制带随机指针的链表
class Solution(object): def copyRandomList(self, head): """ :type head: Node :rtype: Node """ if head is None: return None p = head while p: node = Node(x=p.val, next=p.next) p.next = node p = p.next.next p = head while p: if p.random: p.next.random = p.random.next else: p.next.random = None p = p.next.next p = head.next head = p while p.next: p.next = p.next.next p = p.next return head
原文地址:https://www.cnblogs.com/weswes/p/12078923.html
时间: 2024-10-20 04:38:01