class Solution { public: ListNode* FindFirstCommonNode( ListNode *pHead1, ListNode *pHead2) { if(!pHead1||!pHead2) return NULL; int len1=0,len2=0; ListNode* p1=pHead1,*p2=pHead2; while(p1!=NULL) { p1=p1->next; len1++; } while(p2!=NULL) { p2=p2->next; len2++; } p1=pHead1,p2=pHead2; if(len1>len2) { while(p1&&len1>len2) { p1=p1->next; len1--; } } else { while(p2&&len2>len1) { p2=p2->next; len2--; } } while(p1&&p2) { if(p1!=p2) { p1=p1->next; p2=p2->next; } else return p1; } return NULL; } };