Reverse a singly linked list.
click to show more hints.
Hint:
A linked list can be reversed either iteratively or recursively. Could you implement both?
贴个递归代码,一次Accept。
public ListNode reverseList(ListNode head) {
if (head == null || head.next == null)
return head;
ListNode temp = head.next;
ListNode reverseHead = reverseList(head.next);
temp.next = hea