Check my this code, again same error : InputMismatchException
Node intersectionOfTwoLinkedLists(Node l1, Node l2) {
/* Code here */
if(l1 == null || l2 == null)
{
return null;
}
Node head1 = l1;
Node head2 = l2;
int count1 = 0;
int count2 = 0;
while(l1 != null)
{
count1++;
l1 = l1.next;
}
while(l2 != null)
{
count2++;
l2 = l2.next;
}
int diff = count1 - count2;
while(diff > 0)
{
head1 = head1.next;
diff--;
}
while(diff < 0)
{
head2 = head2.next;
diff++;
}
while(head1 != null && head2 != null)
{
if(head1.data == head2.data)
{
return head1;
}
head1 = head1.next;
head2 = head2.next;
}
return null;
}
}