当前位置:网站首页>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;
}
};边栏推荐
- The macrogenome microbiome knowledge you want is all here (2022.7)
- LeetCode 5. Longest Palindromic Substring
- ThreadLocal
- Connect Porsche and 3PL EDI cases
- GeoServer:发布PostGIS数据源
- Vscode setting delete line shortcut [easy to understand]
- One year is worth ten years
- 二、mock平台的扩展
- Seal Library - installation and introduction
- Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
猜你喜欢

Yolov5 practice: teach object detection by hand

Masa framework - DDD design (1)
![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])

Use the API port of the bridge of knowledge and action to provide resources for partners to access

对接保时捷及3PL EDI案例

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

綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東

GeoServer:发布PostGIS数据源

【Leetcode】13. 罗马数字转整数

Penetration tool - intranet permission maintenance -cobalt strike
随机推荐
PWM breathing lamp
One year is worth ten years
二、mock平台的扩展
The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
剑指 Offer 25. 合并两个排序的链表
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
The impact of telecommuting on all aspects of our experience | community essay solicitation
QStyle实现自绘界面项目实战(二)
A case study of college entrance examination prediction based on multivariate time series
Tech talk activity preview | building intelligent visual products based on Amazon kVs
2322. 从树中删除边的最小分数(异或和&模拟)
基于Impala的高性能数仓实践之执行引擎模块
Exploration of mobile application performance tools
Believe in yourself and finish the JVM interview this time
OpenHarmony如何启动远程设备的FA
A few lines of code to complete RPC service registration and discovery
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
vscode设置删除行快捷键[通俗易懂]
Lampe respiratoire PWM
【Leetcode】13. Roman numeral to integer