public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
// 设两个指针,一起循环两条链表
ListNode A = headA,B = headB;
// 两指针未相遇时,一直循环
while(A != B){
// 当两个指针循环完各自的链表就转向对方的链表继续循环,直到相遇退出循环
A = A != null ? A.next : headB;
B = B != null ? B.next : headA;
}
return A;
}
}
https://leetcode-cn.com/problems/intersection-of-two-linked-lists/solution/intersection-of-two-linked-lists-shuang-zhi-zhen-l/



