当前位置:网站首页>Question d'entrevue 02.02. Renvoie l'avant - dernier noeud K
Question d'entrevue 02.02. Renvoie l'avant - dernier noeud K
2022-06-11 08:55:00 【C'est moi.】
leetcodeBouton de force
Titre:Questions d'entrevue 02.02. Retour à l'avant - dernière k Noeuds
Description:Réaliser un algorithme,Trouvez l'avant - dernier de la liste unidirectionnelle k Noeuds.Renvoie la valeur de ce noeud.
Comment résoudre le problème
1、Pointeur rapide et lent;
Code original##
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;
}
};
边栏推荐
- Sword finger offer 62 The last remaining number in the circle
- 端口占用问题,10000端口
- PVC 塑料片BS 476-6 火焰传播性能测定
- Matlab学习8-图像处理之线性与非线性锐化滤波、非线性平滑滤波
- SAP ABAP internal table classification, addition, deletion, modification and query
- (2) Analysis of AAC source code from the perspective of architecture design - my livedata
- 剑指 Offer 10- II. 青蛙跳台阶问题
- 哪些Apple设备支持这次系统更新?来看你的旧Apple设备支持最新系统吗
- C language printing diamond
- 【node】npm部分
猜你喜欢

(1) AAC opening - lifecycle, livedata, ViewModel and source code analysis skills of core component principles (Reprint)

复制的代码格式混乱怎么办?

Sword finger offer 62 The last remaining number in the circle

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

leetcode - 518. Change II

TextView文本大小自动适配与TextView边距的去除

File system check of the root filesystem failed

c语言打印心形

马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup

MATLAB R2022a 安装教程
随机推荐
BS 7176 fire resistance test for upholstered furniture
MySQL & Oracle database capacity query
K8s application (IV) - build a redis5 cluster (for direct external access)
E. X的放大与缩小(运算符重载)
c语言打印心形
leetcode - 518. Change II
Usage and difference between map and set in JS
K8S应用(四)—— 搭建redis5 集群(可供外部直接访问)
File system check of the root filesystem failed
TextView文本大小自动适配与TextView边距的去除
Android interview transcript (carefully sorted out)
En45545-2 R26 vertical combustion test introduction
剑指 Offer 10- II. 青蛙跳台阶问题
Award winning survey | how Apache pulsar lived in 2022, you the final say
Why is the string class final decorated
203. 移除链表元素
leetcode - 230. 二叉搜索树中第K小的元素
(二)从架构设计角度分析AAC源码-我的LiveData
Standardized compilation knowledge
Android 面试笔录(精心整理篇)