/**
* public class ListNode {
* int val;
* ListNode next = null;
*
* ListNode(int val) {
* this.val = val;
* }
* }
*
*/
import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
ArrayList<Integer> integers = new ArrayList<>();
while (listNode != null) {
integers.add(listNode.val);
listNode = listNode.next;
}
int i = 0, j = integers.size() - 1, tmp;
while (i < j) {
tmp = integers.get(i);
integers.set(i, integers.get(j));
integers.set(j, tmp);
i++;
j--;
}
return integers;
}
}