递归的思想就是把一个整体的问题,拆分成一个个小问题去思考,然后把思考的结果放在递归中,写好限制条件
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。
class Solution {
public ListNode reverseList(ListNode head) {
if(head == null || head.next == null){
return head;
}
ListNode head1 = reverseList(head.next);
head.next.next = head;
head.next = null;
return head1;
}
}
801

被折叠的 条评论
为什么被折叠?



