当前位置:网站首页>面試題 02.02. 返回倒數第 k 個節點
面試題 02.02. 返回倒數第 k 個節點
2022-06-11 08:55:00 【拽拽就是我】
leetcode力扣刷題打卡
題目:面試題 02.02. 返回倒數第 k 個節點
描述:實現一種算法,找出單向鏈錶中倒數第 k 個節點。返回該節點的值。
解題思路
1、快慢指針;
原代碼##
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;
}
};
边栏推荐
- SAP abap 字段符号
- 2130. 链表最大孪生和
- PHP uploading large files for more than 40 seconds server 500
- Screening frog log file analyzer Chinese version installation tutorial
- [Clickhouse column] user initialization of new library role
- 标准化编写知识
- 马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup
- SQL basic query
- leetcode - 739. 每日温度
- GCC AVR(Atmel Studio+ AVR Studio)如何将结构体数组定义在程序存储器(flash)空间并进行读操作
猜你喜欢

Codetop - sort odd ascending even descending linked list

Create a nodejs based background service using express+mysql

剑指 Offer 10- II. 青蛙跳台阶问题

(一)aac开篇-核心组件原理之Lifecycle、LiveData、ViewModel与源码分析技巧(转载)

Matlab学习7-图像处理之线性平滑滤波

端口占用问题,10000端口

M1 芯片指南:M1、M1 Pro、M1 Max 和 M1 Ultra

c语言打印心形

Android interview transcript (carefully sorted out)

How to apply for BS 476-7 sample for display? Is it the same as the display
随机推荐
Sword finger offer 51 Reverse pair in array
How many items should the indoor intumescent fire retardant coating meet according to BS 476-21 fire resistance standard?
Textview text size auto fit and textview margin removal
leetcode - 518. Change II
Award winning survey | how Apache pulsar lived in 2022, you the final say
Supplementary provision plan codeworks round 760 (Div. 3)
【C语言-数据存储】数据在内存中是怎样存储的?
What is the process of en 1101 flammability test for curtains?
c语言打印心形
En45545-2 R26 vertical combustion test introduction
682. 棒球比赛
Wood board ISO 5660-1 heat release rate mapping test
K8s application (IV) - build a redis5 cluster (for direct external access)
876. 链表的中间结点
Getting started with Zipkin
CodeTop - 排序奇升偶降链表
Codetop - sort odd ascending even descending linked list
Matlab学习9-图像处理之非线性锐化滤波
typescript高阶特性一 —— 合并类型(&)
Zipkin入门