

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
ListNode A = headA, B = headB;
while(A != B){
A = A == null ? headB : A.next;
B = B == null ? headA : B.next;
}
return A;
}
}
这篇文章介绍了如何使用Java实现一个Solution类来找出两个单链表的交点。通过while循环遍历两个链表,当它们相遇时返回交点节点。
782

被折叠的 条评论
为什么被折叠?



