当前位置:网站首页>Les derniers noeuds K de la liste jz22
Les derniers noeuds K de la liste jz22
2022-04-23 02:41:00 【Rosita.】
Liens vers les sujets:L'avant - dernier de la ListekNoeuds_Le problème de la vache_Filet de taureaux
Attention:
1.Recherche de violence:Trouvez d'abord la longueur de la listelen,Si moins dek,Retourne à NULL,Pas moins dek,Allons - y.len-k- Non.,C'est ce qui s'est passé.kEmplacement et éléments suivants
2.Pointeur rapide et lent:Pointeur lent vers le noeud de tête,Le pointeur rapide passe en premierkPas,Plus long que la longueur de la liste de liens renvoie NULL,Si le pointeur rapide arrive à la fin,Le pointeur lent pointe verskNoeuds.
Table des matières
Méthode 1:Recherche de violence
Méthode 2:Pointeur rapide et lent
Méthode 1:Recherche de violence
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
class Solution {
public:
/**
* Nom de la classe dans le Code、Nom de la méthode、Nom du paramètre spécifié,Ne pas modifier,Renvoie directement la valeur spécifiée par la méthode
*
*
* @param pHead ListNodeCatégorie
* @param k intTaille
* @return ListNodeCatégorie
*/
ListNode* FindKthToTail(ListNode* pHead, int k) {
int len = 0;
ListNode *p = pHead;
while(p){
len++;
p = p->next;
}
if(len < k) return NULL;
p = pHead;
for(int i = 0 ; i < len-k; ++i){
p = p->next;
}
return p;
}
};
Méthode 2:Pointeur rapide et lent
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
class Solution {
public:
/**
* Nom de la classe dans le Code、Nom de la méthode、Nom du paramètre spécifié,Ne pas modifier,Renvoie directement la valeur spécifiée par la méthode
*
*
* @param pHead ListNodeCatégorie
* @param k intTaille
* @return ListNodeCatégorie
*/
ListNode* FindKthToTail(ListNode* pHead, int k) {
ListNode* fast = pHead ,*slow = pHead;
//Le pointeur rapide passe en premierkPas
for(int i = 0; i < k; ++i){
if(fast != nullptr){
fast = fast->next;
}else{
return slow = nullptr;
}
}
while(fast){
fast = fast->next;
slow = slow->next;
}
return slow;
}
};
版权声明
本文为[Rosita.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230240052827.html
边栏推荐
- 重大危险源企业如何保障年底前完成双预防机制数字化建设任务
- JZ22 链表中倒数最后k个结点
- Understanding process (multithreading primary)
- Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23
- Fashion MNIST dataset classification training
- Interim summary (Introduction + application layer + transportation layer)
- 013_ Analysis of SMS verification code login process based on session
- leetcode 烹饪料理
- 【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
- JVM运行时数据区(一)
猜你喜欢

SQL server2019 cannot download the required files, which may indicate that the version of the installer is no longer supported. What should I do

16、 Anomaly detection

Fashion MNIST dataset classification training

This is how the power circuit is designed

Interim summary (Introduction + application layer + transportation layer)

JVM runtime data area (I)
![[xjtu Computer Network Security and Management] session 2 Cryptographic Technology](/img/b0/263e8dcbfeb2ce9f504a9c8eb76b07.png)
[xjtu Computer Network Security and Management] session 2 Cryptographic Technology

C语言 171. 最近回文数

MySQL JDBC编程

php+mysql對下拉框搜索的內容修改
随机推荐
005_ redis_ Set set
Web learning record (medium)
The second day of learning rhcsa
解决win7 中powershell挖矿占用CPU100%
Rhcsa second day operation
The importance of ERP integration to the improvement of the company's system
Using go language to build web server
[XJTU computer network security and management] Lecture 2 password technology
win查看端口占用 命令行
PHP sorting of interview questions on April 20, 2022
Yes, from today on, our fans can participate in Netease data analysis training camp for free!
【unity3D】直播间滚动式弹幕效果
Real math problems in 1958 college entrance examination
WordPress calls the specified page content. 2 get_ children()
Understanding process (multithreading primary)
Execute external SQL script in MySQL workbench and report error
Renesas electronic MCU RT thread development and Design Competition
Handwritten memory pool and principle code analysis [C language]
Go语言web中间件的使用
OCR识别PDF文件