方法一:递归实现
public ListNode reverseList(ListNode head) {
if(head == null || head.next == null){
return head;
}
ListNode pre = reverseList(head.next);
head.next.next = head;
head.next = null;
return pre;
}
方法二:双指针方式
public ListNode reverseList(ListNode head) {
ListNode front = null;
while(head != null){
ListNode back = head.next;
head.next = front;
front = head;
head = back;
}
return front;
}