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;
    }
};
原文地址:https://www.cnblogs.com/-citywall123/p/13945711.html