// 链表相交
// 输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3
// 输出:Intersected at '8'
public static ListNode getIntersectionNode(ListNode headA,ListNode headB){
if(headA==null||headB==null)return null;
ListNode pA=headA,pB=headB;
while (pA!=pB){
pA=pA==null?headB:pA.next;
pB=pB==null?headA:pB.next;
}
return pA;
}
链表相交技巧
最新推荐文章于 2024-08-26 23:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)