Node *intersectionOfTwoLinkedLists(Node *headA, Node *headB)
{
if (headA == NULL || headB == NULL) {
return NULL;
}
Node* l1= headA;
Node* l2= headB;
int c1=0;int c2=0;
while( l1!=l2 && l1!=NULL && l2!=NULL)
{
l1=l1->next;
l2=l2->next;
if(l1==NULL)
{
if(c1==0)
l1=headB;
else
break;
c1++;
}
if(l2==NULL)
{
if(c2==0)
l2=headA;
else
break;
c2++;
}
}
if(l1==l2)
return l1;
else
return NULL;
}
