C++ 最实用最快速的方法
/**
* 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;
while(head){
res.insert(res.begin(),head->val);
head = head->next;
}
return res;
}
}; 暴力解决,简单实用。