Swap Nodes in Pairs(交换链表相邻的两个结点)
2016-05-26 13:56
645 查看
交换链表相邻的两个结点
/** * 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) { if(head == null || head.next == null) return head; ListNode list = head.next; ListNode list1 = list.next; list.next = head; head.next = swapPairs(list1); return list; } }
相关文章推荐
- 25. Reverse Nodes in k-Group
- leetcode---Swap Nodes in Pairs
- node
- Nodejs正则表达式函数之match、test、exec、search、split、replace使用详解
- NodeJs初学者经典入门解析
- Elasticsearch NoNodeAvailableException 问题解决
- nodejs安装
- nodejs MODEL层 封装(一)
- 222. Count Complete Tree Nodes
- Yslow on Nodejs server
- DOMNodeInserted监听div内容改变
- node+fis3搭建
- hadoop2.5集群迁移namenode
- nodejs 返回html页面--使用 ejs 模板
- nodejs
- leetcode 19. Remove Nth Node From End of List
- leetcode 25. Reverse Nodes in k-Group——很值得一看的链表题
- Nodejs学习笔记(二)
- Nodejs学习笔记(一)
- node.js读取本地的文件