当前位置:网站首页>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;}边栏推荐
- What are some useful performance testing tools recommended? Performance testing report charging standards
- 力扣练习——56 寻找右区间
- LCD驱动端与设备端名称匹配过程分析(Tiny4412)
- SMIC CIM localization project suspended?Rising software: not shut down, changed to remote development!
- Licking Exercise - 59 From Binary Search Trees to Greater Sum Trees
- 力扣练习——61 根据字符出现频率排序
- 可视化服务编排在金融APP中的实践
- 力扣练习——64 最长和谐子序列
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- 使用JMeter进行MySQL的压力测试
猜你喜欢

rider内Mono脚本找不到引用资源

Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability

A little self-deprecating deconstruction about farmers "code"

gpu-admission 源码分析

LAXCUS分布式操作系统安全管理

VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决

Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using

Article take you understand interrupt the key driver of polling mechanism

Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control

Network sockets (UDP and TCP programming)
随机推荐
配置druid数据源「建议收藏」
微信小程序提交审核历史版本记录从哪里查看
【Redis】内存回收策略
Article take you understand interrupt the key driver of polling mechanism
10 个 Reduce 常用“奇技淫巧”
LeetCode 369. Plus One Linked List(链表加1)
APP automation testing practice based on UiAutomator2+PageObject mode
3款不同类型的自媒体免费工具,有效提高创作、运营效率
被面试官问到消息队列的丢失、重复与积压问题该如何回答
力扣练习——58 验证二叉搜索树
LeetCode 86. 分隔链表
Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using
jlink 与 swd 接口定义
制品库是什么?
越折腾越好用的 3 款开源 APP
WeChat applet, global variables change in one place and the state in other places also changes.
可视化服务编排在金融APP中的实践
What are some useful performance testing tools recommended? Performance testing report charging standards
老板加薪!看我做的WPF Loading!!!
LeetCode 19. Delete the Nth last node of the linked list