输入一个链表的头结点,按照 从尾到头 的顺序返回节点的值。
返回的结果用数组存储。
class Solution { public: vector<int> printListReversingly(ListNode* head) { vector<int> ans; for (auto p = head; p; p = p->next) ans.push_back(p->val); reverse (ans.begin(), ans.end()); return ans; } };
标签:head,到头,链表,vector,从尾,ans From: https://www.cnblogs.com/leetothemoon/p/16971673.html