当前位置:网站首页>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;
}
};
边栏推荐
- Auto SEG loss: automatic loss function design
- LVGL 8.2 Simple Colorwheel
- LeetCode Algorithm 86. 分隔链表
- 我们公司使用 7 年的这套通用解决方案,打通了几十个系统,稳的一批!
- Mysql database foundation: TCL transaction control language
- Gd32 RT thread RTC driver function
- LVGL 8.2 Checkboxes as radio buttons
- CSDN daily one practice 2021.11.06 question 1 (C language)
- Voir le changement technologique à travers la Légion Huawei (5): Smart Park
- Skill combing [email protected] control a dog's running on OLED
猜你喜欢

微信推出图片大爆炸功能;苹果自研 5G 芯片或已失败;微软解决导致 Edge 停止响应的 bug|极客头条...
![[STL source code analysis] iterator](/img/e8/7c69cf6e96ecfa053494397a21eff0.jpg)
[STL source code analysis] iterator

透过华为军团看科技之变(五):智慧园区

pytorch 筆記 torch.nn.BatchNorm1d

Sarsa笔记
![[机缘参悟-34]:光锥之内皆命运](/img/3e/9f5630ba382df7f7ce00705445cef8.jpg)
[机缘参悟-34]:光锥之内皆命运
![[deep learning] common methods for deep learning to detect small targets](/img/c6/8f0549864992a1554397bad16dad4d.jpg)
[deep learning] common methods for deep learning to detect small targets

7 大轻量易用的工具,给开发者减压提效,助力企业敏捷上云 | Techo Day 精彩回顾...

DQN笔记

Auto Seg-Loss: 自动损失函数设计
随机推荐
CP2112使用USB转IIC通信教学示例
File sharing server
断路器HystrixCircuitBreaker
Ant financial's written test question: what can be quantified in the requirements document? [Hangzhou multi tester] [Hangzhou multi tester \wang Sir]
Voir le changement technologique à travers la Légion Huawei (5): Smart Park
Rejuvenated Dell and apple hit each other, and the two old PC enterprises declined rapidly
Double-DQN笔记
Deep dive kotlin synergy (16): Channel
20万奖金池!【阿里安全 × ICDM 2022】大规模电商图上的风险商品检测赛火热报名中!...
59 websites programmers need to know
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
SGD has many improved forms. Why do most papers still use SGD?
[STL source code analysis] iterator
Pytorch notes: validation, model eval V.S torch. no_ grad
Deep dive kotlin Xie Cheng (17): Actor
Input a decimal data, convert to 8, using the sequence stack
Collectors.toMap应用
【STL源码剖析】容器(待补充)
TypeScript–es5中的类,继承,静态方法
LVGL 8.2 menu from a drop-down list