当前位置:网站首页>LeetCode 24. Swap nodes in linked list pairwise
LeetCode 24. Swap nodes in linked list pairwise
2022-08-10 11:57:00 【Water dish pen】
Original URL: https://leetcode.cn/problems/swap-nodes-in-pairs/submissions/
About the exchange; https://blog.csdn.net/qq_34501351/article/details/126203341?spm=1001.2014.3001.5501 This question is also a problem of exchange; because the target node of the exchange can be obtained; a virtual head node is introduced; the previous node of the target node can be better obtained;easier;
public ListNode swapPairs(ListNode head) {ListNode dummyHead = new ListNode(-1);dummyHead.next = head;ListNode cur = dummyHead;ListNode node = head;while(node != null) {ListNode frist = node;ListNode second = node.next;// There is only one number, no need to change it, return the resultif(second == null) {return dummyHead.next;}frist.next = second.next;second.next = frist;cur.next = second;cur = frist;node = frist.next;}return dummyHead.next;}边栏推荐
猜你喜欢

mpf6_Time Series Data_quandl_更正kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull

电脑怎么设置屏幕息屏时间(日常使用分享)

怎么加入自媒体,了解这5种变现模式,让账号快速变现
![[Brave food, not afraid of the linked list of brushing questions] Merging of ordered linked lists](/img/06/9d49fc99ab684f03740deb2abc38e2.png)
[Brave food, not afraid of the linked list of brushing questions] Merging of ordered linked lists

Where can I view the version record of WeChat applet submission review history?
![[E-commerce operation] Do you really understand social media marketing (SMM)?](/img/5b/6682c613305deb3dc15401077d38a0.png)
[E-commerce operation] Do you really understand social media marketing (SMM)?

零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?

2016,还是到了最后

StoneDB Document Bug Hunting Season 1

嘉为蓝鲸荣获工信部“数字技术融合创新应用解决方案”
随机推荐
使用.NET简单实现一个Redis的高性能克隆版(六)
常量及数据类型你还记得多少?
力扣练习——63 找到字符串中所有字母异位词
LeetCode 146. LRU 缓存
单目操作符(含原码反码补码转换)
软件架构简介
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
越折腾越好用的 3 款开源 APP
HDU 4372:Count the Buildings (Stirling数)
Module 9 - Designing an e-commerce seckill system
A little self-deprecating deconstruction about farmers "code"
LeetCode 109. 有序链表转换二叉搜索树
LeetCode 92. 反转链表 II
【Redis】内存回收策略
十年架构五年生活-09 五年之约如期而至
力扣练习——60 二叉搜索子树的最大键值和
再有人问你分布式事务,把这篇扔给他
LeetCode 237. 删除链表中的节点
LeetCode50天刷题计划(Day 18—— 搜索旋转排序数组(8.50-12.00)
VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决