class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if(pListHead == NULL || pListHead->next == NULL)
return pListHead;
ListNode* cur = pListHead;
int count = 0;
while(cur){
count++;
cur = cur->next;
}
if(k > count)
{
return nullptr;
}
int tmp = count-k;
for(int i = 0; i < tmp; i++)
{
pListHead = pListHead->next;
}
return pListHead;
}
};
链表中倒数第K个节点
原创
©著作权归作者所有:来自51CTO博客作者小猪小猪呼噜噜的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
4.带头节点的双链表的实现(C语言)
双链表基本运算的代码实现,前插、后插操作
双链表 头结点 插入操作 删除操作 -
链表中倒数第K个节点 (Java实现)
输入一个链表,输出该链表中倒
java 链表 快慢指针 -
22题 链表中倒数第k个节点
这道题对我来说难点就是临界点不好找,总是找不准慢指针啥时候开始移
链表 剑指offer 倒数第k个 两个指针 初始化 -
算法-查找链表中倒数第K个节点
算法-查找链表中倒数第K个节点
System i++ 算法实现 -
单链表查找倒数第k个节点
单链表查找倒数第k个节点
查找 单链表 节点 -
链表中倒数第k个结点
题目描述: 输入一个链表,输出该链表中倒数第k个结
链表 结点 i++