题解 | #反转链表#递归解法,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
};

简单的递归

全部评论

相关推荐

VirtualBool:都去逗他了?
点赞 评论 收藏
分享
评论
10
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务