/*
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 cur = head ;
ListNode pre = head ;
if( head == null){return null;} // 头结点不存在或者k值不合理,返回空
if( k<= 0){return null;}
for(int i = 0; i < k-1; i++){ //pre指针先行k-1步,k值太大,过了表头,那么返回空
if(pre.next != null){
pre = pre.next;
}else{
return null;
}
}
while(pre.next != null){ //两个指针同时后移,当先行指针为空时,说明cur指到第k位;
pre = pre.next ;
cur = cur.next ;
}
return cur;
}
}