示例:
输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
private ListNode reverse(ListNode head){
if (head == null || head.next == null)return head;
ListNode temp = head.next;
ListNode newHead = reverse(head.next);
temp.next = head;
head.next = null;
return newHead;
}
public ListNode reverseList2(ListNode head) {
if (head == null || head.next == null) return head;
ListNode newHead = null;
while (head != null) {
ListNode tmp = head.next;
head.next = newHead;
newHead = head;
head = tmp;
}
return newHead;
}