题目:输入一个链表,输出该链表中倒数第k个结点
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
ListNode *p = pListHead;
if(pListHead == NULL) return NULL;
int cnt = 0;
while(p){
cnt++;
p = p->next;
}
if(cnt<k) return NULL;
for(int i =1;i<cnt-k+1;i++){
pListHead = pListHead->next;
}
return pListHead;
}
};