当前位置:网站首页>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;
}
};
边栏推荐
- Ionic4 drag the ion reorder group component to change the item order
- Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled
- MySQL从入门到精通50讲(三十二)-ScyllaDB生产环境集群搭建
- 19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
- 同事的接口文档我每次看着就头大,毛病多多。。。
- Didi open source agile test case management platform!
- 焕发青春的戴尔和苹果夹击,两大老牌PC企业极速衰败
- Retest the cloud native database performance: polardb is still the strongest, while tdsql-c and gaussdb have little change
- 无心剑中译狄金森《灵魂择其伴侣》
- 科普达人丨漫画图解什么是eRDMA?
猜你喜欢

Deep dive kotlin synergy (16): Channel

第一届中国数字藏品大会即将召开

深潜Kotlin协程(十六):Channel

Migrate full RT thread to gd32f4xx (detailed)

Dow Jones Industrial Average
[email protected] somatosensory manipulator"/>Skill combing [email protected] somatosensory manipulator

Unity Shader - 踩坑 - BRP 管线中的 depth texture 的精度问题(暂无解决方案,推荐换 URP)
[email protected] intelligent instrument teaching aids based on 51 series single chip microcomputer"/>Skill combing [email protected] intelligent instrument teaching aids based on 51 series single chip microcomputer

scratch绘制正方形 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月
![[STL source code analysis] iterator](/img/e8/7c69cf6e96ecfa053494397a21eff0.jpg)
[STL source code analysis] iterator
随机推荐
焕发青春的戴尔和苹果夹击,两大老牌PC企业极速衰败
Skill combing [email protected] somatosensory manipulator
LVGL 8.2 Image styling and offset
MATLAB image histogram equalization, namely spatial filtering
断路器HystrixCircuitBreaker
The two e-commerce bigwigs' lacy news screens represent the return of e-commerce to normal, which will be beneficial to the real economy
[proteus simulation] Arduino uno led simulated traffic light
透過華為軍團看科技之變(五):智慧園區
My in-depth remote office experience | community essay solicitation
Overview of currency
[机缘参悟-34]:光锥之内皆命运
Gd32 RT thread RTC driver function
Auto SEG loss: automatic loss function design
Matplotlib notes: contour & Contour
Pandora IOT development board learning (HAL Library) - Experiment 1 running lantern (RGB) experiment (learning notes)
[rust weekly database] num bigint - large integer
Anhui "requirements for design depth of Hefei fabricated building construction drawing review" was printed and distributed; Hebei Hengshui city adjusts the pre-sale license standard for prefabricated
iptables目标TPROXY
Pycharm项目使用pyinstalle打包过程中问题及解决方案
& and - > priority