/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
ListNode *pA = headA, *pB = headB;
while (pA != pB) {
pA = pA == NULL ? headB : pA->next;
pB = pB == NULL ? headA : pB->next;
}
return pA;
}
};
双指针:找公共链表节点,只要两个是相交的,路程长度一致,速度一致,一定会相交
Banana!
来源:CSDN
作者:之井
链接:https://blog.csdn.net/mdzz_z/article/details/103895437