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

题目描述:

输入一个链表,按链表值从尾到头的顺序返回一个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();
}
原文地址:https://www.cnblogs.com/3yleaves/p/9588575.html