/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param listNode ListNode类
* @return int整型一维数组
* @return int* returnSize 返回数组行数
*/
int* printListFromTailToHead(struct ListNode* listNode, int* returnSize ) {
// write code here
int *arr=NULL;
int cnt=0;
struct ListNode* p=listNode;
while(p!=NULL) //遍历链表,计算链表长度
{
p=p->next;
cnt++;
}
arr=(int *)malloc(cnt*sizeof(int));
*returnSize=cnt;
p=listNode;
while(p!=NULL)
{
arr[--cnt]=p->val; //从后往前把链表里面的值放入arr数组
p=p->next; //下一个
}
return arr;
}