当前位置:网站首页>剑指 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;
}
};边栏推荐
- Analysis of how to prevent virus in industrial computer
- Penetration tool - intranet permission maintenance -cobalt strike
- LeetCode 1. Sum of two numbers
- unity Hub 登錄框變得很窄 無法登錄
- 基于Impala的高性能数仓实践之执行引擎模块
- 伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
- MOSFET器件手册关键参数解读
- DGraph: 大规模动态图数据集
- [cloud native] briefly talk about the understanding of flume, a massive data collection component
- Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

大廠面試總結大全

AP and F107 data sources and processing

Privacy computing technology innovation and industry practice seminar: Learning

PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
![[essay solicitation activity] Dear developer, RT thread community calls you to contribute](/img/31/11409606718e0f4837f4cc572172a3.png)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute

Seal Library - installation and introduction

Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...

畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权

Use of openpose

Yolov5 practice: teach object detection by hand
随机推荐
畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
[leetcode] 14. Préfixe public le plus long
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
MOSFET器件手册关键参数解读
【Leetcode】14. 最长公共前缀
移动应用性能工具探索之路
GeoServer:发布PostGIS数据源
上传代码到远程仓库报错error: remote origin already exists.
Hard core! One configuration center for 8 classes!
Use of openpose
System Verilog实现优先级仲裁器
【Leetcode】13. 罗马数字转整数
Global and Chinese market of desktop hot melt equipment 2022-2028: Research Report on technology, participants, trends, market size and share
【Leetcode】14. Longest Common Prefix
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
AP and F107 data sources and processing
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
PWM控制舵机
Interpretation of key parameters in MOSFET device manual
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东