当前位置:网站首页>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;
}
};
边栏推荐
- Analysis of EN 45545 R24 oxygen index test method
- Codetop - sort odd ascending even descending linked list
- Matlab learning 9- nonlinear sharpening filter for image processing
- Textview text size auto fit and textview margin removal
- c语言打印心形
- C语言打印菱形
- [node] NPM part
- 【C语言-数据存储】数据在内存中是怎样存储的?
- AS 3744.1标准中提及ISO8191测试,两者测试一样吗?
- 【新手上路常见问答】关于数据可视化
猜你喜欢

剑指 Offer 40. 最小的k个数

处理RAW格式的图像,需要什么软件?

显示器要申请BS 476-7 怎么送样?跟显示屏一样吗

The leader asked me to rewrite the test code. Should I do the same?

Create a nodejs based background service using express+mysql

leetcode - 460. LFU 缓存
![[Clickhouse column] user initialization of new library role](/img/00/a11fb1a8e38ed4e0634839160c8ead.png)
[Clickhouse column] user initialization of new library role

leetcode - 518. Change II

Screaming Frog Log File Analyser 中文版安装教程

Notes on MySQL core points
随机推荐
E. X的放大与缩小(运算符重载)
MySQL核心点笔记
剑指 Offer 51. 数组中的逆序对
Standardized compilation knowledge
Why is the string class final decorated
Getting started with Zipkin
PVC 塑料片BS 476-6 火焰传播性能测定
leveldb简单使用样例
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
EN 45545 R24氧指数测试方法解析
【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程
Port occupancy problem, 10000 ports
EN45545-2 R26垂直燃烧测试介绍
光伏板怎么申请ASTM E108阻燃测试?
窗帘做EN 1101易燃性测试过程是怎么样的?
剑指 Offer 10- II. 青蛙跳台阶问题
Wood board ISO 5660-1 heat release rate mapping test
SQL basic query
Intelligent control theory question bank
AS 3744.1标准中提及ISO8191测试,两者测试一样吗?