Skip to content

Commit 73b87e0

Browse files
authored
Create 590. N-ary Tree Postorder Traversal
1 parent faf2019 commit 73b87e0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

590. N-ary Tree Postorder Traversal

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
vector<int> ans;
4+
5+
void solve(Node* root) {
6+
if (root == 0) {
7+
return;
8+
}
9+
10+
for (const auto& node : root->children) {
11+
solve(node);
12+
}
13+
14+
ans.push_back(root->val);
15+
return;
16+
}
17+
18+
vector<int> postorder(Node* root) {
19+
solve(root);
20+
return ans;
21+
}
22+
};

0 commit comments

Comments
 (0)