/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
class Solution {
public:
ListNode* FindKthToTail(ListNode* pHead, int k) {
/*int length = 0;
ListNode* cur = pHead;
while( cur )
{
++length;
cur = cur->next;
}
if(length < k) return nullptr;
length -= k;
while(length--)
{
pHead = pHead->next;
}
return pHead;*/
ListNode* fast = pHead ,*slow = pHead;
for(int i=0; i < k ; ++i)
{
if(fast == nullptr) return fast;
fast = fast->next;
}
while(fast!=nullptr)
{
slow = slow->next;
fast = fast->next;
}
return slow;
}
};