反转链表

1. 递归

  1. public ListNode reverseList(ListNode head) {
  2. //递归
  3. if(head == null || head.next == null){
  4. return head;
  5. }
  6. ListNode newHead = reverseList(head.next);
  7. head.next.next = head;
  8. head.next = null;
  9. return newHead;
  10. }