题解 | #从尾到头打印链表#
从尾到头打印链表
http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035
tip:head本身就是一个实体,形如{val: "1234", next: headNext}
/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function printListFromTailToHead(head)
{
let array01 = [];
while(head) { // 思考为什么不是head.next
array01.push(head.val);
head = head.next;
}
return array01.reverse();
// write code here
}
module.exports = {
printListFromTailToHead
};