输入一个链表,输出该链表中倒数第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) { if(head == null){
return head;
}
int count = 0;
ListNode list = head; while(list != null){
count++;
list = list.next;
}
if(k > count){
return null;
} ListNode node = head;
for(int i = 0; i < count -k; i++){
node = node.next;
}
return node; }
}