题解 | #从尾到头打印链表#
从尾到头打印链表
http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035
static int g_input[10000] = {0};
int *printListFromTailToHead(struct ListNode *listNode, int *returnSize) {
int idx = 0;
while (listNode != NULL) {
(*returnSize)++;
g_input[idx++] = listNode->val;
listNode = listNode->next;
}
for (int i = 0, j = *returnSize - 1; i < j; i++, j--) {
g_input[i] ^= g_input[j] ^= g_input[i] ^= g_input[j];
}
return g_input;
}