/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *findFirstCommonNode(ListNode *headA, ListNode *headB) {
auto a=headA,b=headB;
while(a!=b)
{
if(a) a=a->next;
else a=headB;
if(b) b=b->next;
else b=headA;
}
return a;
}
};