题目:https://www.nowcoder.com/questionTerminal/75e878df47f24fdc9dc3e400ec6058ca
//用递归的思路,保留头指针即可
public class Solution {
public ListNode ReverseList(ListNode head) { return reverse(null, head); } ListNode temp; ListNode first; public ListNode reverse(ListNode last, ListNode head) { if(head != null) { reverse(head, head.next); head.next = last; temp = head; }else { first = last; } return first; }
}