public ListNode FindKthToTail(ListNode head, int k) {
if (head == null) {
return null;
}
ListNode first = head;
ListNode second = head;
int count = 0;
while (count < k) {
if (first == null) {
return null;
}
count++;
first = first.next;
}
while (first != null) {
first = first.next;
second = second.next;
}
return second;
}
链表中倒数最后k个结点
最新推荐文章于 2025-12-16 16:07:35 发布
458

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



