当前位置:网站首页>剑指 Offer 22. 链表中倒数第k个节点
剑指 Offer 22. 链表中倒数第k个节点
2022-07-02 14:21:00 【anieoo】
solution:
快慢指针,快指针先走k步,然后快慢指针一起向前走,当快指针走到终点的时候,慢指针就是倒数第k个。
class Solution {
public:
ListNode* getKthFromEnd(ListNode* head, int k) {
ListNode *fast = head;
ListNode *slow = head;
while(fast != NULL && k) {
fast = fast->next;
k--;
}
while(fast != NULL) {
fast = fast->next;
slow = slow->next;
}
return slow;
}
};边栏推荐
- Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
- Seal Library - installation and introduction
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- 超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
- 对接保时捷及3PL EDI案例
- In MySQL and Oracle, the boundary and range of between and precautions when querying the date
- MOSFET器件手册关键参数解读
- 社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
- 学习周刊-总第60期-2022年第25周
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
猜你喜欢

Easy language ABCD sort

一文看懂:数据指标体系的4大类型

Penetration tool - intranet permission maintenance -cobalt strike

【Leetcode】13. Roman numeral to integer

Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)

你想要的宏基因组-微生物组知识全在这(2022.7)

对接保时捷及3PL EDI案例

What is normal distribution? What is the 28 law?

Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP

小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求
随机推荐
机器学习-感知机模型
Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
寒门再出贵子:江西穷县考出了省状元,做对了什么?
< IV & gt; H264 decode output YUV file
深度学习图像数据自动标注[通俗易懂]
上传代码到远程仓库报错error: remote origin already exists.
LeetCode 5. Longest Palindromic Substring
LSF basic command
Error when uploading code to remote warehouse: remote origin already exists
P6774 [noi2020] tears in the era (block)
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
Global and Chinese market of jacquard looms 2022-2028: Research Report on technology, participants, trends, market size and share
七张图,学会做有价值的经营分析
PWM breathing lamp
IP address translation address segment
Download blender on Alibaba cloud image station
C语言自定义函数的方法
pwm呼吸燈
uboot的作用和功能
【Leetcode】14. Longest Common Prefix