What wrong with this solution?


  • 0
    Y
    class Solution(object):
    def getIntersectionNode(self, headA, headB):
        """
        :type head1, head1: ListNode
        :rtype: ListNode
        """
        if not headA:
            return None
        if not headB:
            return None
        
        while headA != None and headB != None:
            if headA.val == headB.val:
                return headA
            if headA.val < headB.val:
                headA = headA.next
                continue
            else:
                headB = headB.next
        return None

  • 1
    K

    Comparing val instead of node.

    assuming List is in order (by value)

    Try when these are the values:

    A:         4 → 2
                    ↘
                       1 → 2 → 3
                     ↗            
    B:     4 → 2 → 5
    

Log in to reply
 

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