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