public ListNode reverseList(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode curr = head;
ListNode prev = null;
while (curr != null) {
ListNode temp = curr.next;
curr.next = prev;
prev = curr;
curr = temp;
}
return prev;
}
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;
}
原文:https://www.cnblogs.com/init-qiancheng/p/14617908.html