ListNode* getKthFromEnd(ListNode* head, int k) {
ListNode* fast=head;
ListNode* slow=head;
//因为头结点开始 所以要从1开始
for(int i=1;i<k;i++){
fast=fast->next;
//倒数节点超过节点数
if(fast == NULL){
return NULL;
}
}
//当fast到尾结点
while(fast->next!=NULL){
fast=fast->next;
slow=slow->next;
}
return slow;
}
标签:head,slow,ListNode,删除,fast,节点,next,倒数第
From: https://www.cnblogs.com/lwx11111/p/16757332.html