public class Solution {
ArrayList<Integer> resultArray = new ArrayList<>();
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
Stack<Integer> s = new Stack<Integer>();
ListNode p = listNode;
while(p != null) {
s.push(p.val);
p = p.next;
}
while (!s.empty()) {
resultArray.add(s.pop()); //利用栈的特性
}
return resultArray;
}
}