当前位置:网站首页>Algorithme leetcode 86. Liste des liens séparés
Algorithme leetcode 86. Liste des liens séparés
2022-06-30 10:55:00 【Alex 996.】
Liens vers les sujets:86. Liste de liens séparés
Ideas
Algorithmes:Simulation
Structure des données:Liste des liens
Idées:(J'ai d'abord essayé d'échanger des pointeurs en place,Il a réussi à s'évanouir et à ouvrir la solution.)
D'abord, créez deux noeuds virtuels,Utilisé séparément pour maintenir les exigences inférieures àxEt plus dexNode of,Puis traversez la liste,Un noeud est rencontré pour déterminer quel type,Ensuite, mettez - le derrière le noeud virtuel correspondant.
Code
C++
class Solution {
public:
ListNode* partition(ListNode* head, int x) {
ListNode *small = new ListNode(0), *large = new ListNode(0);
ListNode *smallHead = small, *largeHead = large;
while (head != nullptr) {
if (head->val < x) {
small->next = head;
small = small->next;
} else {
large->next = head;
large = large->next;
}
head = head->next;
}
large->next = nullptr;
small->next = largeHead->next;
return smallHead->next;
}
};
边栏推荐
- Migrate full RT thread to gd32f4xx (detailed)
- 焕发青春的戴尔和苹果夹击,两大老牌PC企业极速衰败
- [STL source code analysis] container (to be supplemented)
- Gd32 RT thread DAC driver function
- 同事的接口文档我每次看着就头大,毛病多多。。。
- pytorch 笔记 torch.nn.BatchNorm1d
- MySQL导出sql脚本文件
- Qt之实现QQ天气预报窗体翻转效果
- LVGL 8.2 menu from a drop-down list
- scratch绘制正方形 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月
猜你喜欢
随机推荐
Collectors. Tomap application
iptables目标TPROXY
【Proteus仿真】Arduino UNO LED模拟交通灯
05_ Node JS file management module FS
JS FAQs
文件共享服务器
Agile Development: super easy to use bucket estimation system
Typescript – classes in Es5, inheritance, static methods
Q-Learning笔记
我们公司使用 7 年的这套通用解决方案,打通了几十个系统,稳的一批!
List介绍
科普达人丨漫画图解什么是eRDMA?
基于HAL库的按键(KEY)库函数
Criu enables hot migration
19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
SGD has many improved forms. Why do most papers still use SGD?
Skill sorting [email protected]+adxl345+ Motor vibration + serial port output
Review of mathematical knowledge: curve integral of the second type
Mysql database foundation: constraint and identification columns
LeetCode Algorithm 86. 分隔链表









