[LeetCode 024] Swap Nodes in Pairs
2016-02-18 04:08
585 查看
Swap Nodes in Pairs
![](https://images2015.cnblogs.com/blog/643208/201602/643208-20160218040802081-562772347.png)
Implementation
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode swapPairs(ListNode head) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null && current.next.next != null) { ListNode p1 = current.next; ListNode p2 = current.next.next; p1.next = p2.next; p2.next = p1; current.next = p2; current = p1; } return dummy.next; } }
相关文章推荐
- LeetCode 116. Populating Next Right Pointers in Each Node
- win7安装nodejs
- node相关
- 使用PM2将Node.js的集群变得更加容易
- Windows环境下的NodeJS+NPM+Bower安装配置
- leetcode 237. Delete Node in a Linked List
- nodejs模块发布及命令行程序开发
- Nodes之Get和Post请求
- LeetCode - 19. Remove Nth Node From End of List
- Ubuntu 12.10 添加 node 应用为自启动服务
- windows下nodejs环境配置
- nodejs中npm常用命令
- nodejs修复ipa处理过的png图片
- webstorm+nodejs开发环境配置(1)
- windows 下安装nodejs及其配置环境
- [备忘]ubuntu安装node.js
- Node.js的事件循环
- IOS学习:常用第三方库(GDataXMLNode:xml解析库)
- node.js使用经验记录
- 解析Node.js异常处理中domain模块的使用方法