/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
#include <cstdio>
class Solution {
public:
//双指针
//让每个指针都走两次链表,当步数相等时,两个指针会相遇,就是链表相交的点
ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
ListNode* tmp1 = pHead1;
ListNode* tmp2 = pHead2;
while(tmp1 != tmp2){
if(tmp1 != nullptr)
tmp1 = tmp1->next;
else if(tmp1 == nullptr)
tmp1 = pHead2;
if(tmp2 != nullptr)
tmp2 = tmp2->next;
else if(tmp2 == nullptr)
tmp2 = pHead1;
}//tmp1 == tmp2
return tmp1;
}
};