1 2 3 4 5 6 7 8 9 10 11 12 13
| class Solution { public: void go(Node* root, vector<int> & ans){ for(int i=0;i<root->children.size();++i) go(root->children[i], ans); ans.push_back(root->val); } vector<int> postorder(Node* root) { vector<int> ans; if(!root) return ans; go(root, ans); return ans; } };
|