/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
// ListNode* ret;
if(!pHead1 || !pHead2) {
return nullptr;
}
ListNode *headA = pHead1, *headB = pHead2;
while(headA != headB) {
headA = (headA == nullptr) ? pHead2 : headA->next;
headB = (headB == nullptr) ? pHead1 : headB->next ;
}
return headA;
}
};