美文网首页
2.3.3 链表

2.3.3 链表

作者: Ching_Lee | 来源:发表于2018-05-24 20:29 被阅读0次

面试题6:从尾到头打印链表

输入一个链表,从尾到头打印链表每个节点的值。

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function printListFromTailToHead(head)
{
   let arr=[];
   let p=head;
    while(p!=null){
        arr.push(p.val);
        p=p.next;
    }
    return arr.reverse();
}

相关文章

网友评论

      本文标题:2.3.3 链表

      本文链接:https://www.haomeiwen.com/subject/qovtdftx.html