Sword To Offer 003 - 从尾到头打印链表 2018-03-12 Sword To Offer Contents 从尾到头打印链表DesicriptionSolution 从尾到头打印链表 Desicription输入一个链表,从尾到头打印链表每个节点的值。 Solution123456789101112131415161718192021/*** struct ListNode {* int val;* struct ListNode *next;* ListNode(int x) :* val(x), next(NULL) {* }* };*/class Solution {public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> res; while(head != nullptr) { res.push_back(head->val); head = head->next; } reverse(res.begin(), res.end()); return res; }};