输入一个链表,从尾到头打印链表每个节点的值。
class Solution {
public:vector<int> printListFromTailToHead(ListNode* head) {
vector<int> list;
while(head!=NULL)
{
list.push_back(head->val);
head=head->next;
}
reverse(list.begin(),list.end());
cout<<head->val<<" ";
return list;
}
};