Did any one get this error? ERROR: linked structure was modified

  • 0

    Attached is my code. Does any one know why I get this error? "ERROR: linked structure was modified"
    Thanks for your time.

    def getIntersectionNode(self, headA, headB):
        if headA == None or headB == None:
            return None
        hA = headA
        while hA.next != None:
            hA = hA.next
        hA.next = headB
        slow = headA
        fast = headA
        while fast != None and fast.next != None:
            slow = slow.next
            fast = fast.next.next
            if slow == fast:
                p1 = headA
                p2 = slow
                while p1 != p2:
                    p1 = p1.next
                    p2 = p2.next
                return p1
        return None

  • 0

    Take care of the note #2 :

    The linked lists must retain their original structure after the
    function returns.

  • 0

    Have you figured out how to maintain the linked structure? I break the circle before I return the result. but it still complains that the linked structure was modified

Log in to reply

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