LeetCode 24 Swap Nodes In Pairs

这个题简单点,用个head.next.next传下去操作就可以了。

 1 class Solution {
 2     public ListNode swapPairs(ListNode head) {
 3         if (head == null || head.next == null) {
 4             return head;
 5         }
 6         ListNode newHead = swapPairs(head.next.next);
 7         ListNode tail = head.next;
 8         head.next = newHead;
 9         tail.next = head;
10         return tail;
11     }
12 }
原文地址:https://www.cnblogs.com/mayinmiao/p/8488307.html