当前位置:网站首页>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;
}
};
边栏推荐
- Viewing technological changes through Huawei Corps (V): smart Park
- Collectors. Tomap application
- 基于HAL库的按键(KEY)库函数
- Skill combing [email protected] somatosensory manipulator
- Remember the experience of an internship. It is necessary to go to the pit (I)
- LVGL 8.2 Image styling and offset
- The number of users of the home-made self-developed system exceeded 400million, breaking the monopoly of American enterprises, and Google repented
- Input a decimal data, convert to 8, using the sequence stack
- Typescript – classes in Es5, inheritance, static methods
- CSDN daily one practice 2021.11.06 question 1 (C language)
猜你喜欢
软件测试工程师面试基础题(应届生和测试小菜必备)最基础的面试题
Viewing technological changes through Huawei Corps (V): smart Park
文件共享服务器
Dell et Apple, deux entreprises de PC établies, se sont effondrées rapidement
Sarsa笔记
MySQL导出sql脚本文件
Dickinson's soul chooses its companion
数学知识复习:第二型曲线积分
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
Every time I look at my colleagues' interface documents, I get confused and have a lot of problems...
随机推荐
js常见问题
The two e-commerce bigwigs' lacy news screens represent the return of e-commerce to normal, which will be beneficial to the real economy
Deep dive kotlin Xie Cheng (17): Actor
国产自研系统的用户突破4亿,打破美国企业的垄断,谷歌后悔不迭
Matplotlib notes: contour & Contour
蚂蚁金服笔试题:需求文档有什么可以量化的【杭州多测师】【杭州多测师_王sir】...
7 大轻量易用的工具,给开发者减压提效,助力企业敏捷上云 | Techo Day 精彩回顾...
The number of users of the home-made self-developed system exceeded 400million, breaking the monopoly of American enterprises, and Google repented
透過華為軍團看科技之變(五):智慧園區
iptables目标TPROXY
WireGuard简单配置
Ionic4 drag the ion reorder group component to change the item order
无心剑中译狄金森《灵魂择其伴侣》
[rust daily] the first rust monthly magazine on January 22, 2021 invites everyone to participate
Gd32 RT thread ota/bootloader driver function
File sharing server
Cp2112 teaching example of using USB to IIC communication
Pytorch notes torch nn. BatchNorm1d
List介绍
List introduction