public class Solution {
public ListNode reverseInPairs(ListNode head) {
// corner case
if (head == null || head.next == null) {
return head;
}
// 记录一下第二、三个节点
ListNode N2 = head.next;
ListNode N3 = head.next.next;
// subproblem:是以N3为头的LinkedList
ListNode subHead = reverseInPairs(N3);
//把所有的结点关系连起来
N2.next = head;
head.next = subHead;
return N2;
}
}
拓展延伸
LinkedList