/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param pHead1 ListNode类
* @param pHead2 ListNode类
* @return ListNode类
*/
struct ListNode* FindFirstCommonNode(struct ListNode* pHead1, struct ListNode* pHead2) {
// write code here
struct ListNode* pHead3 = pHead2;
while(pHead1 != NULL){
while(pHead3!= NULL){
if(pHead1 == pHead3){
return pHead3;
}
pHead3 = pHead3->next;
}
pHead3 = pHead2;
pHead1 = pHead1->next;
}
return NULL;
}

京公网安备 11010502036488号