当前位置:网站首页>Sword finger offer 22 The penultimate node in the linked list
Sword finger offer 22 The penultimate node in the linked list
2022-07-02 17:12:00 【anieoo】
Original link : The finger of the sword Offer 22. Last in the list k Nodes
solution:
Speed pointer , Let's go first k Step , Then the pointer moves forward quickly and slowly , When the fast pointer reaches the end , The slow pointer is the penultimate k individual .
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;
}
};边栏推荐
- C语言自定义函数的方法
- [essay solicitation activity] Dear developer, RT thread community calls you to contribute
- jsp 和 servlet 有什么区别?
- How openharmony starts FA of remote devices
- L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
- 基于Impala的高性能数仓实践之执行引擎模块
- 远程办公对我们的各方面影响心得 | 社区征文
- John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
- Method of C language self defining function
- How to transfer business data with BorgWarner through EDI?
猜你喜欢

酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东

TCP congestion control details | 2 background

Lampe respiratoire PWM

寒门再出贵子:江西穷县考出了省状元,做对了什么?

Error when uploading code to remote warehouse: remote origin already exists
![L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])

Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights

Believe in yourself and finish the JVM interview this time

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

配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
随机推荐
Easy language ABCD sort
对接保时捷及3PL EDI案例
What is generics- Introduction to generics
【Leetcode】13. Roman numeral to integer
C语言中sprintf()函数的用法
< IV & gt; H264 decode output YUV file
Deep learning image data automatic annotation [easy to understand]
Kubernetes three open interfaces first sight
[leetcode] 14. Préfixe public le plus long
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
uboot的作用和功能
vscode设置删除行快捷键[通俗易懂]
Masa framework - DDD design (1)
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
<四> H264解码输出yuv文件
深度学习图像数据自动标注[通俗易懂]
基于多元时间序列对高考预测分析案例
pwm呼吸燈
体验居家办公完成项目有感 | 社区征文