package 剑指offer_初级;
public class 剑指_Offer_06_从尾到头打印链表 {
public class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
class Solution {
public int[] reversePrint(ListNode head) {
int a[]=new int[0];
if(head==null){
return a;
}
int length=1;
ListNode node=head;
while(head.next!=null){
length++;
head=head.next;
}
int[] arr=new int[length];
while(node.next!=null){
arr[length-1]=node.val;
length--;
node=node.next;
}
arr[0]=node.val;
return arr;
}
}
}
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/