/*
输入一个链表,输出该链表中倒数第k个结点。
/
/
struct ListNode {
int val;
struct ListNode next;
ListNode(int x) :
val(x), next(NULL) {
}
};/
/*
nullptr关键字表示空指针
/
class Solution {
public:
ListNode FindKthToTail(ListNode* pListHead, unsigned int k) {
unsigned int count=0,i=1;
ListNode* p=pListHead;
while(pListHead)
{
pListHead=pListHead->next;
count++;
}
if(k>count)
{
return nullptr;
}
count=count-k+1;
while(p)
{
if(i==count)
{
return p;
}
p=p->next;
i++;
}
}
};