题目描述
输入一个链表,输出该链表中倒数第k个结点。
public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
ListNode s = head;
ListNode q = head;
//链表长度
int i = 0;
while(q != null){
q = q.next;
i++;
}
//倒数第K个节点
int x = 0;
while(x != (i-k)&&s!= null){
s = s.next;
x++;
}
return s;
}
}