问题描述:输入一个链表,按链表从尾到头的顺序返回一个ArrayList。
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> value;
if(head!=NULL)
{
value.insert(value.begin(),head->val);
while(head->next!=NULL)
{
value.insert(value.begin(),head->next->val);
head = head->next;
}
}
return value;
}
};