当前位置:网站首页>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;
}
};
边栏推荐
- 有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
- 13、Darknet YOLO3
- How to transfer business data with BorgWarner through EDI?
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- Un an à dix ans
- john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
- Yolov5 practice: teach object detection by hand
- Leetcode1380: lucky numbers in matrix
- LeetCode 5. Longest Palindromic Substring
- OpenPose的使用
猜你喜欢
PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
智能垃圾桶(五)——点亮OLED
基于多元时间序列对高考预测分析案例
PWM controlled steering gear
QStyle实现自绘界面项目实战(二)
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
Penetration tool - intranet permission maintenance -cobalt strike
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
How openharmony starts FA of remote devices
随机推荐
Talk about an experience of job hopping and being rejected
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
Exploration of mobile application performance tools
深度之眼(三)——矩阵的行列式
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
体验居家办公完成项目有感 | 社区征文
【Leetcode】13. 罗马数字转整数
OpenHarmony如何启动远程设备的FA
MySQL port
Does digicert SSL certificate support Chinese domain name application?
linux安装postgresql + patroni 集群问题
深度学习图像数据自动标注[通俗易懂]
移动应用性能工具探索之路
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
Interpretation of key parameters in MOSFET device manual
Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
PWM controlled steering gear
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
LeetCode 5. Longest Palindromic Substring
一文看懂:数据指标体系的4大类型