/*
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==NULL||k==0) return NULL;
ListNode *p=pListHead,*r=pListHead;
for(unsigned int n=1;n!=k;++n) {
p=p->next;
if(p==NULL) return NULL;
}
while(p->next!=NULL){
r=r->next;
p=p->next;
}
return r;
}
};
剑指offer:链表中倒数第k个结点
最新推荐文章于 2024-08-16 09:29:32 发布