WRY

Where Are You?
You are on the brave land,
To experience, to remember...

0%

算法随记 【2024年02月】

练习收获

练习题目

590. N-ary Tree Postorder Traversal

Version 1

递归遍历

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;
}
};