index
title: 链表中倒数第 date: 2019-08-21T11:00:41+08:00 draft: false categories: offer
题目
解题思路
public ListNode FindKthToTail(ListNode head, int k) {
if (head == null) {
return null;
}
ListNode cursor = head;
ListNode cursorK = head;
int i = 0;
while (cursorK != null) {
cursorK = cursorK.next;
if (i >= k) {
cursor = cursor.next;
}
i++;
}
if (i < k) {
return null;
}
return cursor;
}Last updated