反转链表题使用递归出现空指针异常
class Solution {
ListNode res =new ListNode();
ListNode cur = res;
public ListNode reverseList(ListNode head) {
if (head != null && head.next != null) { reverseList(head.next); }
cur.next = head;
cur = cur.next;
**if(cur != null&&cur.next != null){ cur.next = null;}**这段代码如果不加入cur !=null就会出现空指针异常不知道为啥
return res.next;
}
}