/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindKthToTail(ListNode* head, unsigned int k) {
if (k < 0) return nullptr;
ListNode* temp = head;
while (k -- && temp) temp = temp->next;
if (k != -1) return nullptr;
while (temp) {
temp = temp->next;
head = head->next;
}
return head;
}
};

京公网安备 11010502036488号