AcWing 17. 从尾到头打印链表(c语言)
原题链接
简单
作者:
Sky_
,
2020-09-23 21:35:56
,
所有人可见
,
阅读 1348
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* Note: The returned array must be malloced, assume caller calls free().
*/
int arr[100000];
int* printListReversingly(struct ListNode* head) {
struct ListNode * pre = NULL;
struct ListNode * cur = head;
while(cur)
{
struct ListNode * next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
int i = 0;
while(pre)
{
//printf("%d ", pre->val);
arr[i++] = pre->val;
pre = pre->next;
}
return arr;
}