Python Solution using dictionary


  • 0
    D

    Is this solution good?

    
    def getIntersectionNode(self, headA, headB):
            
            if not headA or not headB:
                return
            
            p={}
            while headA:
                p[headA]=1
                headA=headA.next
            while headB:
                try:
                    if p[headB]==1:
                        return headB
                except KeyError:
                    headB=headB.next
                    
            return None
    

Log in to reply
 

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