Python Solution

  • 0
    def copyRandomList(self, head):
            :type head: RandomListNode
            :rtype: RandomListNode
            if head is None:
            old_new_map = dict()
            old_node = head
            while old_node is not None:
                rln = RandomListNode(old_node.label)
                old_new_map[old_node] = rln
                old_node =
            for on, nn in old_new_map.items():
                if is not None:
           = old_new_map[]
                if on.random is not None:
                    nn.random = old_new_map[on.random]
            return old_new_map[head]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.