class Solution {
public int[] reversePrint(ListNode head) {
if (head == null) {
return new int[0];
}
ListNode origin = head;
int counter = 1;
while (head.next != null) {
counter++;
head = head.next;
}
int[] is = new int[counter];
for (int i = counter - 1; i >= 0; i--) {
is[i] = origin.val;
origin = origin.next;
}
return is;
}
}
image.png