/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public int[] printListReversingly(ListNode head) {
if(head==null)
return null;
ListNode pre=null;
ListNode node=head;
ListNode next=null;
int count=1;
while(node.next!=null){
next=node.next;
node.next=pre;
pre=node;
node=next;
count++;
}
node.next=pre;
int nums[]=new int[count];
int i=0;
while(node!=null){
nums[i++]=node.val;
node=node.next;
}
return nums;
}
}