双指针
public class Solution { public ListNode ReverseList(ListNode head) { if (head == null) { return null; } else { ListNode next = null; ListNode pre = null; while (head != null) { next = head.next; head.next = pre; pre = head; head = next; } return pre; } } }
递归
public class Solution { public ListNode ReverseList(ListNode head) { if (head == null || head.next == null) return head; ListNode last = ReverseList(head.next); head.next.next = head; head.next = null; return last; } }