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