• + 0 comments

    Using the dictionaries in python. One of the easiest and time efficient ways

    def findMergeNode(head1, head2):
        temp1 = head1
        temp2 = head2
        check_dict = {}
        while temp1!=None:
            check_dict[temp1]= True
            temp1 = temp1.next
        while temp2!=None:
            if check_dict.get(temp2)==True:
                return temp2.data
            temp2 = temp2.next
        return None