当前位置:网站首页>Interview question 02.02 Return the penultimate node
Interview question 02.02 Return the penultimate node
2022-06-11 08:55:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject : Interview questions 02.02. Go back to the last k Nodes
describe : Implement an algorithm , Find the bottom of the list k Nodes . Returns the value of the node .
Their thinking
1、 Speed pointer ;
Source code ##
class Solution {
public:
int kthToLast(ListNode* head, int k) {
ListNode *slow = head, *fast = head;
for (int i = 0; i < k; ++i) {
fast = fast->next;
}
while (fast) {
fast = fast->next;
slow = slow->next;
}
return slow->val;
}
};
边栏推荐
- What are the requirements of the drive housing UL 2043?
- 剑指 Offer 40. 最小的k个数
- K8S应用(四)—— 搭建redis5 集群(可供外部直接访问)
- Cron expressions in scheduled tasks
- Android 面试笔录(精心整理篇)
- Sword finger offer 51 Reverse pair in array
- Not eligible for getting processed by all beanpostprocessors
- leetcode - 460. LFU 缓存
- Supplement 2: circle returning to origin
- Codetop - sort odd ascending even descending linked list
猜你喜欢

Installation (detailed illustration) and use of SVN

Screening frog log file analyzer Chinese version installation tutorial

Iso8191 test is mentioned in as 3744.1. Are the two tests the same?

AS 3744.1标准中提及ISO8191测试,两者测试一样吗?

C language printing heart
![[Clickhouse column] user initialization of new library role](/img/00/a11fb1a8e38ed4e0634839160c8ead.png)
[Clickhouse column] user initialization of new library role

M1 chip guide: M1, M1 pro, M1 Max and M1 ultra

Sword finger offer 51 Reverse pair in array

【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程

Intelligent control theory question bank
随机推荐
ActiveMQ simple tutorial, suitable for beginners, learning notes yyds
445. 两数相加 II
九九乘法表
Are the test methods of CMVSS TSD No. 302 and 49 CFR 571.302 the same
Textview text size auto fit and textview margin removal
Can not connect to local MySQL server through socket ‘/tmp/mysql. sock (2)‘
String类为何final修饰
利用docker-compose搭建redis5集群
SAP abap 字段符号
(1) AAC opening - lifecycle, livedata, ViewModel and source code analysis skills of core component principles (Reprint)
PHP解决中文显示乱码
CMVSS TSD No. 302与49 CFR 571.302测试方法是否一样
【新手上路常见问答】关于数据可视化
Screening frog log file analyzer Chinese version installation tutorial
[Clickhouse column] user initialization of new library role
Vagrant mounting pit
剑指 Offer II 036. 后缀表达式
使用express+mysql创建一个基于nodejs的后台服务
Sword finger offer 10- ii Frog jumping on steps
leetcode - 518. 零钱兑换 II