Share my easy and clean python code


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

  • 1
    Y

    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.