当前位置:网站首页>LeetCode Algorithm 328. 奇偶链表
LeetCode Algorithm 328. 奇偶链表
2022-07-30 04:42:00 【Alex_996】
题目链接:328. 奇偶链表
Ideas
算法:遍历
数据结构:链表
思路:话不多说,代码十分通俗易懂,好的代码都不需要注释。
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;
}
};
边栏推荐
- nSoftware.PowerShell.Server.2020
- VisualStudio2022本地调试进入特别慢问题解决
- 1. Get data - requests.get()
- 软件测试员必看!数据库知识mysql查询语句大全
- file system two
- Unity beginner 5 cameras follow, border control and simple particle control (2 d)
- SVN View Username and Password
- Xiamen SenseCore Technology MC3172(1): Introduction and Environment Construction
- Unity3D Application simulation enters the front and background and pauses
- 【软件工程之美 - 专栏笔记】31 | 软件测试要为产品质量负责吗?
猜你喜欢

1315_使用LOOPBACK模拟模式pyserial安装是否成功的测试

Naive Bayes Classification

我的Go+语言初体验——祝福留言小系统,让她也可以感受到你的祝福

MySQL String Concatenation - Various String Concatenation Practical Cases

2.5快速排序

2.6归并排序

swagger usage tutorial - quick use of swagger

动态规划问题(完结篇)

Golang eight-legged text finishing (continuous handling)

解决报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start b
随机推荐
共建共享数字世界的根:阿里云打造全面的云原生开源生态
聊一聊什么是SaaS,以及遇到的问题......
1. 获取数据-requests.get()
KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
2.5 Quick Sort
Shanxi group (enterprises) in the second network security skills competition part problem WP (7)
五、视图解析与模板引擎
Unity3D Application simulation enters the front and background and pauses
2.6归并排序
VisualStudio2022本地调试进入特别慢问题解决
sql statement - how to query data in another table based on the data in one table
SaaS多租户数据隔离的三种解决方案
handler+message [message mechanism]
文件系统二
webService接口
Android Studio 实现登录注册-源代码 (连接MySql数据库)
Requirements design document and the changing role of the product manager
如何与墨西哥大众VW Mexico建立EDI连接
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
POJ1321 chessboard problem (detailed explanation)