Skip to content

Commit a333576

Browse files
committed
#300 Solution as on 18-02-2022 07:30 pm
1 parent 1b9de4c commit a333576

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 589.✅ N-ary Tree Preorder Traversal
2+
3+
class Solution
4+
{
5+
public:
6+
void pre(Node *root, vector<int> &v)
7+
{
8+
if (root != NULL)
9+
{
10+
v.push_back(root->val);
11+
for (auto child : root->children)
12+
pre(child, v);
13+
}
14+
}
15+
16+
vector<int> preorder(Node *root)
17+
{
18+
vector<int> v;
19+
20+
pre(root, v);
21+
22+
return v;
23+
}
24+
};

0 commit comments

Comments
 (0)