/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if(pListHead==nullptr||k==0 )//鲁棒性先类型检查
return nullptr;
ListNode* before=pListHead; //前行
ListNode* after = nullptr;
for ( unsigned int i=0;i<k-1;i++)
{
if(before->next!=nullptr) //这个阶段是不应该到达尾部的
{
before=before->next;
}else
{
return nullptr;
}
}
while(before->next!=nullptr)//走到尾部
{
before=before->next;
after=after->next;
}
return after;
}
};