【leetcode】从尾到头打印链表

 

//利用循环一直到空指针然后申请数组通过递归一层层赋值并返回
int
* reversePrint(struct ListNode* head, int* returnSize){ if(head == NULL){ *returnSize = 0; return malloc(sizeof(int) * 10000); } int *ans = reversePrint(head->next, returnSize); ans[(*returnSize)++] = head->val; return ans; }

 

posted @ 2020-08-22 18:56  温暖了寂寞  阅读(112)  评论(0编辑  收藏  举报