Intersection point


#1

Comment body goes here.

B
int length(ListNode head)
{
int cnt=0;
while(head!=NULL)
{
cnt++;
head=head->next;
}
return cnt;
}
ListNode
Solution::getIntersectionNode(ListNode* A, ListNode* B) {
ListNode *larger,*smaller;
int d,m,n,cnt;
m=length(A);
n=length(B);
d=abs(m-n);
if(m>n)
{
larger=A;
smaller=B;
}
else
{
larger=B;
smaller=A;
}
cnt=0;
while(cnt<d)
{
larger=larger->next;
cnt++;
}
while(larger!=smaller)
{
larger=larger->next;
smaller=smaller->next;
}
return larger;

// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details

}