题解 | #链表中倒数第k个结点#
链表中倒数第k个结点
http://www.nowcoder.com/practice/529d3ae5a407492994ad2a246518148a
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
ListNode *fast=pListHead;
ListNode *slow=pListHead;
while(k--){
if(fast)
fast=fast->next;
else
return NULL;
}
while(fast){
slow=slow->next;
fast=fast->next;
}
return slow;
}
};
查看2道真题和解析