码迷,mamicode.com
首页 > 其他好文 > 详细

剑指offer(3)从尾到头打印链表

时间:2018-09-04 21:42:19      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:col   sub   []   null   链表   pre   返回   var   turn   

题目描述:

输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。

解题代码:

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function printListFromTailToHead(head)
{
    // write code here
    var arr = [];
    if(head == null){
        return arr;
    }
    while(head != null){
        arr.push(head.val);
        head = head.next;
    }
    return arr.reverse();
}

 

剑指offer(3)从尾到头打印链表

标签:col   sub   []   null   链表   pre   返回   var   turn   

原文地址:https://www.cnblogs.com/3yleaves/p/9588575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!