My accepted Python solution: easy to read, hope useful.

  • -8
    def getIntersectionNode(self, headA, headB):
        if headA == None or headB == None:
            return None
        ptr_A = headA
        ptr_B = headB
        # From the test cases, you can see all list are soreted.
        while ptr_A != None and ptr_B != None:
            if ptr_A.val < ptr_B.val:
                ptr_A =
            elif ptr_B.val < ptr_A.val:
                ptr_B =
                return ptr_A
        return None

  • 0

    What if the lists aren't sorted then? The solution should be general enough to not have a specific input that wasn't explicitly specified in the instructions.

  • 0

    good catch songking - I have the exact same question ! All of the solutions seem to assume that the two lists are sorted list with integers . And question doesnt say this at all.

Log in to reply

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