Swap Nodes in Pairs
来源:互联网 发布:ubuntu16 安装mysql 编辑:程序博客网 时间:2024/06/05 02:58
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode swapPairs(ListNode head) { ListNode newHead = new ListNode(0); newHead.next = head; ListNode pre = newHead; while(null != pre.next && null != pre.next.next){ ListNode firstNode = pre.next; ListNode secondNode = pre.next.next; firstNode.next = secondNode.next; secondNode.next = firstNode; pre.next = secondNode; pre = firstNode; } return newHead.next; }}
0 0
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes In Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- 第六周 【项目6-复数模板类】2.1
- netif_start_queue、netif_wake_queue、
- 池子项目上线总结
- 开始Android开发的学习!
- 第九题
- Swap Nodes in Pairs
- 我眼中的产品经理
- 代码积累,猜数价格
- 省选模版复习——线性筛法
- Codeforces Round #298 (Div. 2)A, B, C, D
- PHP中的常量
- CountDownLatch用法
- 第十题
- C++ static关键字!