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

京公网安备 11010502036488号