题解 | #反转链表#

反转链表

https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca

private ListNode ReverseList(ListNode head) {
        if(head==null){
            return null;
        }
        List<ListNode> list=new ArrayList<>();
        list.add(head);
        while (head.next != null){
            list.add(head.next);
            head=head.next;
        }
        for(int i = list.size()-1;i>0;i--){
            list.get(i).next=list.get(i-1);
            if(i-1==0){
                list.get(i-1).next=null;
            }
        }
        return list.get(list.size()-1);
    }

全部评论

相关推荐

昨天 14:27
中山大学 C++
rt,day3就开始接需求
星际探神:你就想 你是水货他们都没面出来 他们也水 管他呢
点赞 评论 收藏
分享
06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务