当前位置:网站首页>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;
}
};
边栏推荐
- Serial port controls steering gear rotation
- What will you do after digital IC Verification?
- IP地址转换地址段
- 入行数字IC验证后会做些什么?
- JS delete substring in string
- Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
- pwm呼吸燈
- 深度学习图像数据自动标注[通俗易懂]
- Talk about an experience of job hopping and being rejected
- MOSFET器件手册关键参数解读
猜你喜欢
Believe in yourself and finish the JVM interview this time
使用知行之桥的API端口,提供资源供合作伙伴访问
数字IC手撕代码--投票表决器
移动应用性能工具探索之路
871. 最低加油次数
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
linux安装postgresql + patroni 集群问题
Linux Installation PostgreSQL + Patroni cluster problem
一文看懂:数据指标体系的4大类型
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
随机推荐
Learning Weekly - total issue 60 - 25th week of 2022
Error when uploading code to remote warehouse: remote origin already exists
Dgraph: large scale dynamic graph dataset
2、 Expansion of mock platform
<四> H264解码输出yuv文件
PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
MySQL port
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
易语言abcd排序
A case study of college entrance examination prediction based on multivariate time series
Use of openpose
剑指 Offer 25. 合并两个排序的链表
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
入行数字IC验证后会做些什么?
System Verilog实现优先级仲裁器
Leetcode1380: lucky numbers in matrix
人生的开始
相信自己,这次一把搞定JVM面试
一年顶十年
Understand one article: four types of data index system