题解 | #反转链表#递归解法,JavaScript

反转链表

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

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function ReverseList(pHead)
{
    if(!pHead || !pHead.next) return pHead;
    
    let newhead = ReverseList(pHead.next);
    pHead.next.next = pHead;
    pHead.next = null;
    
    return newhead;
}
module.exports = {
    ReverseList : ReverseList
};

简单的递归

全部评论

相关推荐

06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
05-11 20:45
门头沟学院 Java
有担当的灰太狼又在摸...:零帧起手查看图片
点赞 评论 收藏
分享
今天 15:12
门头沟学院 运营
点赞 评论 收藏
分享
评论
10
收藏
分享

创作者周榜

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