Leetcode590 N叉树的后序遍历

Leetcode590 N叉树的后序遍历

~~// /*递归法
// // 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> res;
vector<int> postorder(Node* root) {
if(root==nullptr)
	return res;
for(int i=0;i<root->children.size();i++)
{
	postorder(root->children[i]);

}
	res.push_back(root->val);
	return res;
}