一定要看清楚题目是从尾到头打印链表!!!
vector<int> printListFromTailToHead(ListNode* head)
{
vector<int> vec;
if(head == NULL)
{
return vec;
}
ListNode* temp = head;
while(temp != NULL)
{
int data = temp->val;
vec.push_back(data);
temp = temp->next;
}
int len = vec.size();
vector<int> vec2;
for(int i = len - 1;i >= 0;i--)
{
vec2.push_back(vec[i]);
}
return vec2;
}