JAVA语言
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode getKthFromEnd(ListNode head, int k) {
if(head==null||k==0){
return null;
}
ListNode fast=head;
ListNode low =new ListNode(0);
for(int i=0;i<k-1;i++){
if(fast.next!=null)
{
fast=fast.next;
}
else{
return null;
}
}
low=head;
while(fast.next!=null){
fast=fast.next;
low=low.next;
}
return low;
}
}