Why my Python solution got memory limit exceeded? pls help


  • 1
    C
    class Solution(object):
    def getIntersectionNode(self, headA, headB):
        """
        :type head1, head1: ListNode
        :rtype: ListNode
        """
        if headA is None or headB is None:
            return None
        k = headB
        while k.next is not None:
            k = k.next
        k.next = headB
        p = headA
        pos = headA
        q = headA
        flag = 0
        while q.next is not None and q.next.next is not None:
            p = p.next
            q = q.next.next
            if p == q:
                flag = 1
                pos = p
                break
        if flag == 0:
            k.next = None
            return None
        p = headA
        q = pos
        while True:
            p = p.next
            q = q.next
            if p == q:
                k.next = None
                return p

  • 0
    M

    Hmm .. I m running into the same problem , I m getting a memory limit exceeded for my solution as well.


Log in to reply
 

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