题目描述
输入一个链表,输出该链表中倒数第k个结点。
public class Solution {
public ListNode FindKthToTail(ListNode head, int k) {
ListNode pre = head;
ListNode post = head;
for(int i = 0; i < k; i++) {
if(post != null)
post = post.next;
else
return null;
}
while(post != null) {
pre = pre.next;
post = post.next;
}
return pre;
}
}