-
2.10
- 又忘了,注意卡车结构,swap 里是 newHead,也就是 head 的下两个
-
1.24
- lets gooooooo!
-
1.20
- 挖到宝了,和递归反转一样,只不过链接过程不一样
-
11.9
- 其实看图非常好理解
- 当判双空时,return的是head,而不是null
class Solution {
public ListNode swapPairs(ListNode head) {
if(head == null ||head.next == null){
return head;
}
//保存head的下一个
ListNode newHead = head.next;
//head的下一个为递归
head.next = swapPairs(newHead.next);
//篡位
newHead.next = head;
//返回篡位者
return newHead;
}
}
