递归方法
C++代码:
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children; Node() {} Node(int _val, vector<Node*> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public:
vector<int> postorder(Node* root) {
vector<int>res;
post(root,res);
return res;
}
void post(Node*root, vector<int> &res){
if(root==NULL) return;
for(int i=;i<root->children.size();i++){
post(root->children[i],res);
}
res.push_back(root->val);
}
};