当前位置:网站首页>LeetCode Algorithm 328. Parity linked list
LeetCode Algorithm 328. Parity linked list
2022-07-30 04:45:00 【Alex_996】
题目链接:328. 奇偶链表
Ideas
算法:遍历
数据结构:链表
思路:话不多说,The code is very easy to understand,Good code doesn't need comments.
Code
C++
class Solution {
public:
ListNode* oddEvenList(ListNode* head) {
if (head == nullptr || head->next == nullptr || head->next->next == nullptr) return head;
ListNode *oddHead = head, *evenHead = head->next;
ListNode *odd = oddHead, *even = evenHead;
head = head->next->next;
bool oddFlag = true;
while (head != nullptr) {
if (oddFlag) {
odd->next = head;
odd = odd->next;
} else {
even->next = head;
even = even->next;
}
oddFlag = !oddFlag;
head = head->next;
}
odd->next = evenHead;
even->next = nullptr;
return oddHead;
}
};
边栏推荐
- Code open source design and implementation ideas
- MNIST of Dataset: MNIST (handwritten digital image recognition + ubyte.gz file) data set introduction, download, usage (including data enhancement) detailed guide
- MYSQL unique constraint
- Alibaba Cloud's EasyNLP Chinese text image generation model takes you to become an artist in seconds
- Dynamic Programming Problems (End)
- gnss rtcm rtklib Ntrip...
- 2.5 Quick Sort
- 山西省第二届网络安全技能大赛(企业组)部分赛题WP(八)
- 2021 Shandong Province Network Construction and Application Test Questions
- Six, read application configuration + log configuration
猜你喜欢

Verify that the addShutdownHook hook takes effect

山西省第二届网络安全技能大赛(企业组)部分赛题WP(七)

Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction

【线性表】- LeetCode力扣三道练习题详解
![[MRCTF2020]Hello_misc](/img/ea/0faacf6e544b60e3459d8ace4d5f42.png)
[MRCTF2020]Hello_misc

Usage of EFR32 as sniffer for Zigbee/Thread

Plan for many situations in the processing chain

解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b

全流程调度——Azkaban入门与进阶
![[MRCTF2020]Hello_ misc](/img/ea/0faacf6e544b60e3459d8ace4d5f42.png)
[MRCTF2020]Hello_ misc
随机推荐
【 notes 】 the beauty of the software engineering - column 31 | software testing are responsible for the quality of products?
(Problem practice) Conditional probability + weight line segment tree + FWT + suffix array
The VUX Datetime component compute-days-function dynamically sets the date list
Dynamic Programming Problems (End)
模拟问题(中)
labelme的使用技巧
斐波那契数列的递归优化《备忘录递归》
Notes on "The Law of Construction"---Chapter 10 Typical Users and Scenarios
Mini Program wx.miniProgram.navigateTo jump address cannot be tabbar address
【线性表】- LeetCode力扣三道练习题详解
The Complete Go Books - Beginner to Advanced and Web Development
webService接口
Android Studio implements login registration - source code (connecting to MySql database)
sql statement - how to query data in another table based on the data in one table
[C language] Program environment and preprocessing
字符串问题(上)
MySQL operation statement Daquan (detailed)
How does MySql find out the latest data row that meets the conditions?
Double pointer problem (middle)
gnss rtcm rtklib Ntrip...