当前位置:网站首页>Parity rearrangement of Bm14 linked list
Parity rearrangement of Bm14 linked list
2022-07-28 19:10:00 【Love life and programming a】

Ideas :This problem can be solved by skillfully using the correlation between parity
public class Solution {
/** * The class name in the code 、 Method name 、 The parameter name has been specified , Do not modify , Return the value specified by the method directly * * @param head ListNode class * @return ListNode class */
public ListNode oddEvenList (ListNode head) {
// write code here
if(head == null){
return null;
}
// 1: Record the first parity node
ListNode p1Head = head;
ListNode p2Head = head.next;
ListNode p1 = p1Head;
ListNode p2 = p2Head;
// 2: Odd and even nodes use each other to connect their own nodes
// Be careful : The end condition should ensure that the odd node is not empty , Because it depends on the last odd node to connect the first even node
// Therefore, the end condition can be determined according to the odd number of nodes and the even number of nodes
while(p2 != null && p2.next != null){
p1.next = p2.next;
p1 = p1.next;
p2.next = p1.next;
p2 = p2.next;
}
p1.next = p2Head;
return head;
}
}

边栏推荐
- Mongodb database replication table
- Is software testing really as good as online?
- Overview and working principle of single chip microcomputer crystal oscillator
- The difference between --save Dev and --save in NPM
- Is two months of software testing training reliable?
- Win11系统svchost.exe一直在下载怎么办?
- Redis cache avalanche, penetration, breakdown, bloom filter, detailed explanation of distributed lock
- SwiftUI Swift 之正向地理编码与反向地理编码(教程含源码)
- Mongodb database shell command execution
- QT running image
猜你喜欢

真正的 HTAP 对用户和开发者意味着什么?

The wechat installation package has expanded 575 times in 11 years, and the up owner: "98% of the documents are garbage"; Apple App store was exposed to a large number of pornographic apps; Four techn

When unity customizes the editor, let the subclass inherit the inspector display effect of the parent class

The open source of "avoiding disease and avoiding medicine" will not go far

When the new version of easycvr is linked at the same level, the subordinate platform passes up the cause analysis of the incomplete display of the hierarchical directory

Win11系统svchost.exe一直在下载怎么办?

SQL custom automatic calculation

Swiftui component how to implement textfield of hidden part of phone number mask (tutorial includes source code)

How to solve the problem that easycvr device cannot be online again after offline?

EasyCVR设备离线后无法再次上线该如何解决?
随机推荐
软件测试开发基础|测开中的几个工具开发实战
行业落地呈现新进展 | 2022开放原子全球开源峰会OpenAtom OpenHarmony分论坛圆满召开
Implementation of grayscale publishing with haproxy
What does real HTAP mean to users and developers?
“讳疾忌医”的开源走不远
BM16 删除有序链表中重复的元素-II
SwiftUI 组件之如何实现电话号码掩码隐藏部分的文本字段TextField(教程含源码)
3、 Uni app fixed or direct to a certain page
EasyCVR接入设备后播放视频出现卡顿现象的原因分析及解决
QT widget promoted to QWidget
优麒麟系统安装BeyondComare
cv5200无线WiFi通信模块,视频图像传输无线化,实时无线通信技术
Wechat solves the problem of long press selected style
Swiftui component how to implement textfield of hidden part of phone number mask (tutorial includes source code)
Zero knowledge proof: zkp with DDH assumption
Four years later, Debian finally recaptured the "debian.community" domain name!
How to break through the bottleneck of professional development for software testing engineers
【物理应用】水下浮动风力涡轮机的尾流诱导动态模拟风场附matlab代码
MySQL date function
If you want to change to it, does it really matter if you don't have a major?