快慢指针:
时间复杂度:
空间复杂度:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* getKthFromEnd(ListNode* head, int k) {
ListNode* res = head;
while (k--) {
head = head->next;
}
while (head) {
res = res->next;
head = head->next;
}
return res;
}
};
博客提及力扣地址,重点介绍了快慢指针,还涉及快慢指针的时间复杂度和空间复杂度等信息技术相关内容。
524

被折叠的 条评论
为什么被折叠?



