A utility function that returns true if data is present in linked list else return false
boolean isPresent ( Node head , int data ) { Node t = head ; while ( t != null ) { if ( t . data == data ) return true ; t = t . next ; } return false ; } LinkedList getIntersection ( Node head1 , Node head2 ) { HashSet < Integer > hset = new HashSet < > ( ) ; Node n1 = head1 ; Node n2 = head2 ; LinkedList result = new LinkedList ( ) ;