Java 代码
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution
{
public int[] printListReversingly(ListNode head)
{
ListNode cur = head;
int count = 0;
while (cur != null)
{
count ++;
cur = cur.next;
}
int[] l = new int[count];
for (int i = count - 1; i >= 0; i --)
{
l[i] = head.val;
head = head.next;
}
return l;
}
}