运行时间:3ms
占用内存:608k
/**
* 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;
vector<int>::iterator it;
ListNode *idx = head;
while(idx){
it = res.begin();
res.insert(it, idx -> val);
idx = idx -> next;
}
return res;
}
};
真菜啊