/**
* 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 p=headA,q=headB;
int s=0;
if(!p||!q)return NULL;
while(true)
{
if(p==q)
return p;
p=p->next,q=q->next;
if(p==NULL)p=headB,s++;
if(q==NULL)q=headA,s++;
if(s==100)return NULL;
}
}
};