/*
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;
ListNode node = head;
int count = 0;
while (node != null) {
count++; //统计其中链表长度
node = node.next;
}
if (count < k) return null; // 条件判断
ListNode list=head;
for(int i=0;i<count-k;i++){
list=list.next;
}
return list;
}
}
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;
ListNode node = head;
int count = 0;
while (node != null) {
count++; //统计其中链表长度
node = node.next;
}
if (count < k) return null; // 条件判断
ListNode list=head;
for(int i=0;i<count-k;i++){
list=list.next;
}
return list;
}
}