Reverse a singly linked list.
题意:反转单链表
解题思路:一直取下一个节点作为头部
代码:
public class Solution {
public ListNode reverseList(ListNode head) {
return reverseListInt(head,null);
}
public ListNode reverseListInt(ListNode head,ListNode newHead){
if(head == null){
return newHead;
}
ListNode temp = head.next;
head.next = newHead;
return reverseListInt(temp,head);
}
}