Skip to content

Commit 3385ac7

Browse files
committed
Time: 24 ms (39.81%), Space: 11.4 MB (20.83%) - LeetHub
1 parent bc09510 commit 3385ac7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
vector<int> pre;
23+
public:
24+
void dfs(Node* root){
25+
if(root == NULL)
26+
return;
27+
pre.push_back(root->val);
28+
for(auto x: root->children){
29+
dfs(x);
30+
}
31+
}
32+
vector<int> preorder(Node* root) {
33+
dfs(root);
34+
return pre;
35+
}
36+
};

0 commit comments

Comments
 (0)