您现在的位置是:首页 >学无止境 >力扣24题——两两交换链表中节点网站首页学无止境
力扣24题——两两交换链表中节点
简介力扣24题——两两交换链表中节点
#题目

#代码
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode swapPairs(ListNode head) {
ListNode xuni=new ListNode(0,head);
ListNode cur=xuni;
while(cur.next!=null && cur.next.next!=null){
ListNode node1 =cur.next;//第一个节点
ListNode node2 =cur.next.next;//第二个节点
cur.next=node2;
node1.next=node2.next;
node2.next=node1;
cur=cur.next.next;
}
return xuni.next;
}
}
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。





QT多线程的5种用法,通过使用线程解决UI主界面的耗时操作代码,防止界面卡死。...
U8W/U8W-Mini使用与常见问题解决
stm32使用HAL库配置串口中断收发数据(保姆级教程)
分享几个国内免费的ChatGPT镜像网址(亲测有效)
Allegro16.6差分等长设置及走线总结