题解 | #从尾到头打印链表#
从尾到头打印链表
http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035
1.javascript node
node环境下也存在指针,指针如果时head,head.next指向下一个指针;head.val表示指针对应的值
2.数组的方法
插入:
array.unshift(1) 倒序插入
array.shift(2) 正序插入
array.reverse() 倒序
/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function printListFromTailToHead(head)
{
let returnList = [];
while(head){
returnList.unshift(head.val);
head = head.next;
}
return returnList;
// write code here
}
module.exports = {
printListFromTailToHead : printListFromTailToHead
};