/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public int[] printListReversingly(ListNode head) {
Stack<Integer> stk =new Stack<>();
for(ListNode p=head;p!=null;p=p.next)
stk.push(p.val);
int[] res=new int[stk.size()];
int cnt=0;
while(!stk.empty())res[cnt++]=stk.pop();
return res;
}
}