/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
if(head==null||k==0) return null;
ListNode index1=head;
ListNode index2=head;
for(int i=0;i<k-1;i++){
if(index1.next!=null)
index1=index1.next;
else
return null;//链表结点数小于k
}
while(index1.next!=null){
index1=index1.next;
index2=index2.next;
}
return index2;
}
}
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
if(head==null||k==0) return null;
ListNode index1=head;
ListNode index2=head;
for(int i=0;i<k-1;i++){
if(index1.next!=null)
index1=index1.next;
else
return null;//链表结点数小于k
}
while(index1.next!=null){
index1=index1.next;
index2=index2.next;
}
return index2;
}
}