链表反转,我的代码测试通过了,但是提交的时候不行,是什么原因

public class Solution {
    public ListNode ReverseList(ListNode head) {
      if(head.next == null){
          return head;
      }
       ListNode cur = head;
        ListNode prev = null;//辅助指针
        ListNode next = cur.next;
        while(cur!=null){
            cur.next = prev;
            prev = cur;
            cur = next;
            if(cur !=null){
                next = cur.next;//
            }
        }
        return prev;
    }
}

显示有4个测试用例,只通过了3个,想知道通不过的那个测试用例是什么样的?

#Java开发#
全部评论
如果head直接就是空呢,不就空指针异常了
点赞
送花
回复
分享
发布于 2021-10-20 13:37

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务