LeetCode 160. 相交链表

160. 相交链表

解题思路

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
if(headA == null || headB == null) {
return null;
}

ListNode p1 = headA;
ListNode p2 = headB;
while(p1 != p2) {
if(p1 == null) {
p1 = headB;
} else {
p1 = p1.next;
}

if(p2 == null) {
p2 = headA;
} else {
p2 = p2.next;
}
}
return p1;
}
}

LeetCode 160. 相交链表
https://sowink.cn/2026/02/08/LeetCode-160-相交链表/
作者
Xurx
发布于
2026年2月8日
许可协议