题目描述
输入一个链表,输出该链表中倒数第k个结点。
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) {
// write code here
struct ListNode*fast=pListHead,*slow=pListHead;
while(k--)
{
if(fast ==NULL)
{
return NULL;
}
else
{
fast=fast->next;
}
}
while(fast)
{
fast=fast->next;
slow=slow->next;
}
return slow;
}