输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1]
- class Solution {
- 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;
- }
- }