Offer06.从头到尾打印链表/Solution.java
class Solution {
    public int[] reversePrint(ListNode head) {
        LinkedList<Integer> stack = new LinkedList<>();
        while (null != head) {
            stack.add(head.val);
            head = head.next;
        }
        int[] res = new int[stack.size()];

        for (int i = 0; i < res.length; i++) {
            res[i] = stack.removeLast();
        }
        return res;
    }
}