Topic description
Enter a linked list and print the value of each node in the linked list from end to beginning.
/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : * val(x), next(NULL) { * } * }; */ class Solution { public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> vt; while(head != NULL){ vt.push_back(head->val); head = head->next; } int size = vt.size(); int i,j=size - 1,tmp; for(i = 0; i<j ; i++,j--) { tmp = vt[i]; vt[i] = vt[j]; vt[j] = tmp; } return vt; } };