Memory limit exceed?


  • 0
    X

    Hi, I am trying to figure out why this code have "memory limit exceed" error? Thanks!

    Definition for singly-linked list with a random pointer.

    class RandomListNode(object):

    def init(self, x):

    self.label = x

    self.next = None

    self.random = None

    class Solution(object):
    def copyRandomList(self, head):
    """
    :type head: RandomListNode
    :rtype: RandomListNode
    """
    p = head
    while p:
    n = p.next
    copy = RandomListNode(p.label)
    p.next = copy
    copy.next = n
    p = p.next
    p = head
    while p:
    if p.random != None:
    p.next.random = p.random.next
    else:
    p.next.random = None
    p = p.next.next
    p = head
    s = t = RandomListNode(0)
    while p:
    t.next = p.next
    t = t.next
    p = p.next.next
    return s.next


Log in to reply
 

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