输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。
栈,先进后出
/* function ListNode(x){ this.val = x; this.next = null; }*/ function printListFromTailToHead(head) { // write code here const res = []; let pNode = head; while (pNode !== null) { res.unshift(pNode.val); pNode = pNode.next; } return res; }