交换链表中相邻节点的位置
来源:互联网 发布:nginx m3u8 点播 编辑:程序博客网 时间:2024/05/29 08:19
public class Solution { public ListNode swapPairs(ListNode head) { if(head == null) return head; ListNode pre = null; ListNode cur = head; ListNode res = head; boolean flag = true; while (cur != null) { ListNode tmp = cur; ListNode cnext = cur.next; if(pre != null) pre.next = cnext; if(cnext == null) { if(pre != null) pre.next = cur; return res; } ListNode tnext = cnext.next; pre = tmp; cnext.next = cur; cur = tnext; pre.next = null; if(flag) { res = cnext; flag = false; } } return res; }}
阅读全文
0 0
- 交换链表中相邻节点的位置
- 交换单向链表的相邻节点
- 交换链表相邻节点
- leetcode交换相邻的两个节点的值
- Swap Nodes in Pairs 链表交换相邻的节点
- Swap Nodes in Pairs 交换LinkList的相邻节点
- [C++]LeetCode: 109 Swap Nodes in Pairs (交换相邻节点位置)
- 交换链表中的相邻节点
- 单链表相邻两个节点之间交换顺序
- Java单链表基本操作(九)--交换相邻节点对的值
- Java链表指针确实好烦 - 交换链表中连续的两个节点的位置
- 分享个跨browser的交换位置节点的js
- java 交换链表中所有相邻结点的顺序
- 访问相邻的兄弟节点
- 相邻交换
- 交换单链表中相邻的两个点(人搜)
- 变位词排在相邻的位置
- 相邻六边形相对位置的判断
- Summing up Powers LightOJ
- javascript中常用的几种输出方式
- Vue2学习笔记:组件(Component)
- FZU 2261 浪里个浪 (多源最短路)(福州大学第十四届程序设计竞赛)
- java中函数问题Function
- 交换链表中相邻节点的位置
- 操作系统之存储器管理
- 写时拷贝方案分析 copy on write
- MySQL 之数据备份与恢复
- Visual Studio 团队管理器无法连接 TF31003(TF31001,TF31002)
- Some Meritorious Material about WEB . TBC
- Spring入门到精通(二)
- 617. Merge Two Binary Trees
- 电子笔记本的思考(1)(ver0.2)