标签:tle class from 顺序 tno item style col stack
class Solution { public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> res; printListFromTailToHead(res,head); return res; } void printListFromTailToHead(vector<int>& res,ListNode* node) { if(node!=NULL) { printListFromTailToHead(res,node->next); res.push_back(node->val); } } };
class Solution { public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> res; stack<int> stk; int value; ListNode* p = head; while(p!=NULL) { stk.push(p->val); p = p->next; } while(!stk.empty()) { value = stk.top(); stk.pop(); res.push_back(value); } return res; } };
class Solution { public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> res; ListNode* p = head; while(p!=NULL) { res.push_back(p->val); p = p->next; } reverse(res.begin(),res.end()); return res; } };
标签:tle class from 顺序 tno item style col stack
原文地址:https://www.cnblogs.com/dreamstick/p/9496548.html