24. Swap Nodes in Pairs-节点交换|指针
来源:互联网 发布:安卓pad应用推荐 知乎 编辑:程序博客网 时间:2024/05/01 12:49
原题链接:24. Swap Nodes in Pairs
【思路】
本题考查节点的基本操作。每轮循环,如果存在2个节点,则交换前后位置,用p、q两个指针来完成;如果只存在1个节点,则不交换前后位置:
public class Solution { public ListNode swapPairs(ListNode head) { ListNode p = new ListNode(0), q = head, re = p; p.next = head; while((q = p.next) != null && q.next != null) { p.next = q.next; q.next = p.next.next; p.next.next = q; p = q; } return re.next; }}55 / 55 test cases passed. Runtime: 0 ms Your runtime beats 13.35% of javasubmissions.
1 0
- 24. Swap Nodes in Pairs-节点交换|指针
- [LeetCode]Swap Nodes in Pairs 交换节点
- LeetCode 24. Swap Nodes in Pairs(交换节点)
- LeetCode 24. Swap Nodes in Pairs ***** 双节点交换
- Swap Nodes in Pairs 链表两两交换节点@LeetCode
- 【链表&交换邻节点】Swap Nodes in Pairs
- Swap Nodes in Pairs 链表交换相邻的节点
- LeetCode-24 Swap Nodes in Pairs(链表中按要求交换节点)
- LeetCode24 Swap Nodes in Pairs 成对交换链表节点
- Swap Nodes in Pairs 交换LinkList的相邻节点
- [LeetCode] Swap Nodes in Pairs(成对交换节点)
- leetCode 24. Swap Nodes in Pairs (双数交换节点) 解题思路和方法
- Leetcode #24. Swap Nodes in Pairs 链表节点交换 解题报告
- 24. Swap Nodes in Pairs(每两个相邻节点进行一次交换)
- LeetCode-------24. Swap Nodes in Pairs(两两交换)
- Swap Nodes in Pairs 成对交换结点
- [LeetCode]Swap Nodes in Pairs 成对交换
- 24. Swap Nodes in Pairs
- Nginx configure 编译参数
- 如何高效的使用百度谷歌去搜索
- getMeasuredHeight()与getHeight的区别
- 日期计算
- DirectMemory(堆外(Off-Heap)缓存BigMemory的一个实现)
- 24. Swap Nodes in Pairs-节点交换|指针
- 调查问卷生成json字符串
- 1——Introduction to Microservices
- 蓝牙API介绍及基本功能实现
- Android 中 RegistrantList消息处理机制 以android 5.0 MT为例
- struts2 spring集成时struts.xml文件中action的class属性值意义
- git常用命令
- Visual Attention
- 友盟消息推送SDK集成