题目:
解析:
也可以把链表看作一棵树,后续遍历这棵树然后和上图一样,改变指针即可
代码:
public ListNode reverseList(ListNode head) { if(head == null || head.next == null) return head; ListNode newHead = reverseList(head.next); head.next.next = head; head.next = null; return newHead; }