/* 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; ListNode* q = pListHead; int i=1; while(p->next!=NULL) { p=p->next; i++; } if(k>i) return NULL; while(i-k>0) { q=q->next; i--; } return q; } };
原文:https://www.cnblogs.com/loyolh/p/12347082.html