从尾到头打印链表
链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
class Solution {
public int[] reversePrint(ListNode head) {
LinkedList<Integer> sites = new LinkedList<Integer>();
while(head!=null){
sites.add(head.val);
head = head.next;
}
int n = sites.size();
int[] res = new int[n];
for(int i = 0;i<n;i++){
res[i] = sites.removeLast();
}
return res;
}
}