Intersection point of two Linked Lists | Set 3 | Structure of a node of a Linked List ;  ; Function to find the intersection point of the two Linked Lists ; Traverse the first linked list and multiply all values by - 1 ; Update a . data ; Update a ; Traverse the second Linked List and find the value of the first node having negative value ; Intersection point ; Update b ; Function to create linked lists ; Linked List L1 ; Linked List L2 ; Driver Code
class Node : NEW_LINE INDENT def __init__ ( self , d ) : NEW_LINE INDENT self . data = d NEW_LINE self . next = None NEW_LINE DEDENT DEDENT / * Constructor * / def __init__ ( self , d ) : NEW_LINE INDENT self . data = d NEW_LINE self . next = None NEW_LINE DEDENT def intersectingNode ( headA , headB ) : NEW_LINE INDENT a = headA NEW_LINE while ( a ) : NEW_LINE INDENT a . data *= - 1 NEW_LINE a = a . next NEW_LINE DEDENT b = headB NEW_LINE while ( b ) : NEW_LINE INDENT if ( b . data < 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT b = b . next NEW_LINE DEDENT return b NEW_LINE DEDENT def formLinkList ( head1 , head2 ) : NEW_LINE INDENT head1 = Node ( 3 ) NEW_LINE head1 . next = Node ( 6 ) NEW_LINE head1 . next . next = Node ( 9 ) NEW_LINE head1 . next . next . next = Node ( 15 ) NEW_LINE head1 . next . next . next . next = Node ( 30 ) NEW_LINE head2 = Node ( 10 ) NEW_LINE head2 . next = head1 . next . next . next NEW_LINE return head1 , head2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head1 , head2 = formLinkList ( None , None ) NEW_LINE print ( abs ( intersectingNode ( head1 , head2 ) . data ) ) NEW_LINE DEDENT