输入一个链表,输出该链表中倒数第k个结点。
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if (pListHead==NULL) return pListHead;
if(k==0) return NULL;
ListNode* kth=NULL,*end=pListHead;
int count=1;
while(end!=NULL){
if(count++==k){
kth=pListHead;}
else if(count>k){
kth=kth->next;}
end=end->next;
}
return kth;
}
};