/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* findKthToTail(ListNode* head, int k) {
//双指针,也是考研算法题,注意边界
if(!head) return nullptr;
auto p = head,q = head;
while(k--){
if(q) q = q->next;
else return nullptr;
}
while(q) p = p->next,q = q->next;
return p;
}
};