自己写的 debug了一次 是边界条件的问题
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* getKthFromEnd(ListNode* head, int k) {
if(head==nullptr) return head;
ListNode* quick=head;
ListNode* slow=head;
for(int i=0;i<k;i++){
quick=quick->next;
}//quick 先走
while(quick!=nullptr){
slow=slow->next;
quick=quick->next;
}
return slow;
}
};