标签:sig tail counter kth c++ 倒数 public class solution
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if(pListHead == nullptr) return nullptr;
int len = 0;
ListNode* root = pListHead;
while(pListHead != nullptr){
len++;
pListHead = pListHead->next;
}
int counter = len - k;
if(counter < 0) return nullptr;
while(root != nullptr){
if(counter == 0) return root;
root = root->next;
counter--;
}
return nullptr;
}
};
标签:sig tail counter kth c++ 倒数 public class solution
原文地址:https://www.cnblogs.com/theodoric008/p/9534989.html