题目描述
反转一个单链表。
示例:
输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL
思路
1.使用递归的思想求解。
2.具体执行过程,请见下图。
Java代码实现
public ListNode reverseList(ListNode head) { if(head == null || head.next == null) return head; ListNode res = reverseList(head.next); head.next.next = head; head.next = null; return res; }