这个题简单点,用个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 }

 

posted on 2018-03-01 14:38  mayinmiao  阅读(84)  评论(0编辑  收藏  举报