N叉树的前序遍历
class Solution { public: vector<int>p; void dfs(Node* root) { if(root==nullptr) return ; if (root->children.size() == 0){ p.push_back(root->val); return ; } for (int i = 0; i < root->children.size(); i++) { if(root->val!=7777777){ p.push_back(root->val); root->val=7777777; } dfs(root->children[i]); } } vector<int> preorder(Node* root) { dfs(root); return p; } };
等风起的那一天,我已准备好一切