package leetcode_50; /** * * @author pengfei_zheng * 交换相邻节点 */ public class Solution24 { public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public ListNode swapPairs(ListNode head) { if ((head == null)||(head.next == null)) return head; ListNode n = head.next; head.next = swapPairs(head.next.next); n.next = head; return n; } }
LeetCode 24 Swap Nodes in Pairs
原文:http://www.cnblogs.com/zpfbuaa/p/6527363.html