Share my easy and clean python code

  • -3
    def getIntersectionNode(self, headA, headB):
            :type head1, head1: ListNode
            :rtype: ListNode
            dict={} #store all nodes in headA listNode
            while headA:
            while headB:
                if not headB:
                    return None
                if headB in dict:
                    return headB
            return None

  • 1

    But in your solution space complexity is O(n), not O(1)

Log in to reply

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