当前位置:网站首页>剑指 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;
}
};边栏推荐
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
- Seven charts, learn to do valuable business analysis
- 使用知行之桥的API端口,提供资源供合作伙伴访问
- 国内比较好的OJ平台[通俗易懂]
- linux安装postgresql + patroni 集群问题
- What is generics- Introduction to generics
- [North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
- Machine learning perceptron model
- 相信自己,这次一把搞定JVM面试
- 基于Impala的高性能数仓实践之执行引擎模块
猜你喜欢
![john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

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

TCP server communication process (important)

Easy language ABCD sort

Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!

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
![[leetcode] 14. Préfixe public le plus long](/img/70/e5be1a7c2e10776a040bfc8d7711a0.png)
[leetcode] 14. Préfixe public le plus long

LeetCode 1. Sum of two numbers

数字IC手撕代码--投票表决器

Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
随机推荐
What is normal distribution? What is the 28 law?
pwm呼吸灯
LeetCode 1. 两数之和
数字IC手撕代码--投票表决器
Deep learning image data automatic annotation [easy to understand]
国内比较好的OJ平台[通俗易懂]
LeetCode 5. Longest Palindromic Substring
基于多元时间序列对高考预测分析案例
VMware安装win10镜像
MySQL port
LeetCode 6. Zigzag transformation (n-shaped transformation)
The computer comes with software to make the background color of the picture transparent (matting white background)
⌈ 2022 ⌋ how to use webp gracefully in projects
<四> H264解码输出yuv文件
Download blender on Alibaba cloud image station
一文看懂:数据指标体系的4大类型
Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
Seal Library - installation and introduction
远程办公对我们的各方面影响心得 | 社区征文
In MySQL and Oracle, the boundary and range of between and precautions when querying the date