逆序输出这个链表,返回的是数组,可以用数组的unshit
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {number[]}
*/
var reversePrint = function(head) {
let nums = [];
let node = head;
while(node != null){
nums.unshift(node.val);
node = node.next;
}
return nums;
};