当前位置:网站首页>leetcode 24. Exchange the nodes in the linked list in pairs
leetcode 24. Exchange the nodes in the linked list in pairs
2022-07-06 06:18:00 【henujolly】
class Solution {
public ListNode swapPairs(ListNode head) {
ListNode dummyHead = new ListNode();
dummyHead.next = head;
ListNode temp = dummyHead;
while (temp.next != null && temp.next.next != null) {
ListNode node1 = temp.next;
ListNode node2 = temp.next.next;
temp.next = node2;
node1.next = node2.next;
node2.next = node1;
temp = node1;
}
return dummyHead.next;
}
}
边栏推荐
猜你喜欢
随机推荐
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
Resttemplate and feign realize token transmission
Understanding of processes and threads
G - Supermarket
数据库-当前读与快照读
曼哈顿距离和-打印菱形
Application of Lie group in gtsam
MFC 动态创建的对话框及改变控件的大小和位置
MySQL之数据类型
调用链监控Zipkin、sleuth搭建与整合
Isam2 operation process
selenium源码通读·9 |DesiredCapabilities类分析
The latest 2022 review of "graph classification research"
模拟卷Leetcode【普通】1218. 最长定差子序列
Embedded point test of app
對數據安全的思考(轉載)
技术分享 | 常见接口协议解析
On weak network test of special test
Linux regularly backs up MySQL database
曼哈顿距离与曼哈顿矩形-打印回字型矩阵