/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) { ListNode *p1=pHead1; ListNode *p2=pHead2; int x1=0,x2=0; while(p1!=nullptr){ x1++; p1=p1->next; } while(p2!=nullptr){ x2++; p2=p2->next; } ListNode *s1=pHead1; ListNode *s2=pHead2; if(x1>x2){ for(int i=0;i<(x1-x2);i++){ s1=s1->next; } } else if(x2>x1){ for(int i=0;i<(x2-x1);i++){ s2=s2->next; } } do{ if(s1==s2){ return s1; } s1=s1->next; s2=s2->next; }while(s1!=nullptr); return nullptr; } };