LeetCode题解之N-ary Tree Preorder Traversal

1、题目描述

2、问题分析

采用递归方法是标准解法。

3、代码

 1 vector<int> preorder(Node* root) {
 2         vector<int> v;
 3         preNorder(root, v);
 4         return v;
 5     }
 6     
 7     void preNorder(Node *root , vector<int> &v)
 8     {
 9         if (root == NULL)
10             return ;
11         v.push_back(root->val);
12         for (auto it = root->children.begin(); it != root->children.end(); it++) {
13             preNorder(*it, v);
14         }
15     }
原文地址:https://www.cnblogs.com/wangxiaoyong/p/10424397.html