题目描述:
输入一个链表,按链表值从尾到头的顺序返回一个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
时间: 2024-10-07 20:13:15