当前位置:网站首页>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;
}
};边栏推荐
- 一文看懂:数据指标体系的4大类型
- One year is worth ten years
- john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
- 只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!
- What will you do after digital IC Verification?
- Domestic relatively good OJ platform [easy to understand]
- IP address translation address segment
- Dgraph: large scale dynamic graph dataset
- 【Leetcode】14. 最長公共前綴
- <四> H264解码输出yuv文件
猜你喜欢

Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品

DigiCert SSL证书支持中文域名申请吗?

易语言abcd排序

Seven charts, learn to do valuable business analysis

linux安装postgresql + patroni 集群问题

Day 18 of leetcode dynamic planning introduction

相信自己,这次一把搞定JVM面试

Serial port controls steering gear rotation

七张图,学会做有价值的经营分析
![John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
随机推荐
博客主题 “Text“ 夏日清新特别版
小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求
Leetcode1380: lucky numbers in matrix
【Leetcode】14. 最长公共前缀
LeetCode 1. Sum of two numbers
PWM controlled steering gear
Talk about an experience of job hopping and being rejected
How openharmony starts FA of remote devices
MOSFET器件手册关键参数解读
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
Easy language ABCD sort
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
TCP congestion control details | 2 background
linux下配置Mysql授权某个用户远程访问,不受ip限制
uboot的作用和功能
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
Linux Installation PostgreSQL + Patroni cluster problem
Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御