链接:https://leetcode.com/problems/n-ary-tree-postorder-traversal/
题目:求n叉树的后续遍历
思路:与二叉树的后续遍历类似。
代码:
class Solution {
public:
void post(Node* root){
if(!root) return;
for(int i = 0;i < (root->children).size();i++)
post(root->children[i]);
ret.push_back(root->val);
}
vector<int> postorder(Node* root) {
post(root);
return ret;
}
private:
vector<int>ret;
};