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

京公网安备 11010502036488号