题解 | #从尾到头打印链表#

从尾到头打印链表

http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035

没有unshift函数我还真不知道怎么半了 难道先保存在倒序输出?

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function printListFromTailToHead(head)
{
    // write code here
    let res=[]
    let pointer=head
    if (head===null) return []
    while(pointer.next!=null){
        res.unshift(pointer.val)
         pointer=pointer.next
    }
    res.unshift(pointer.val)
    return res
}
module.exports = {
    printListFromTailToHead : printListFromTailToHead
};
全部评论

相关推荐

迷茫的大四🐶:赶快咏鹅启动
点赞 评论 收藏
分享
2025-12-17 12:08
门头沟学院 产品经理
牛客85811352...:1希音不知道算不算大厂 2完全符合,过得很舒服, 3确实只有杂活 领导找我续签到明年3、4月我要继续吗。主要是边实习边秋招这段时间还是有点累
什么是优秀的实习经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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