Skip to content

Commit 56a73ad

Browse files
committed
Time: 11 ms (78.54%), Space: 15.3 MB (49.47%) - LeetHub
1 parent 4f294ef commit 56a73ad

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
// Definition for a Node.
3+
class Node {
4+
public:
5+
int val;
6+
vector<Node*> children;
7+
8+
Node() {}
9+
10+
Node(int _val) {
11+
val = _val;
12+
}
13+
14+
Node(int _val, vector<Node*> _children) {
15+
val = _val;
16+
children = _children;
17+
}
18+
};
19+
*/
20+
21+
class Solution {
22+
public:
23+
vector<int> postorder(Node* root) {
24+
vector<int> ans;
25+
26+
27+
function<void(Node*)> dfs = [&](Node* root) {
28+
if (!root) return;
29+
for (auto& v : root->children) {
30+
dfs(v);
31+
}
32+
ans.push_back(root->val);
33+
};
34+
35+
dfs(root);
36+
return ans;
37+
}
38+
};

0 commit comments

Comments
 (0)