LeetCode—590. N-ary Tree Postorder Traversal


//url:https://leetcode.com/problems/n-ary-tree-postorder-traversal/description/

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector children;

    Node() {}

    Node(int _val, vector _children) {
        val = _val;
        children = _children;
    }
};
*/
class Solution {
public:
    vector postorder(Node* root) {
        postorderEx(root);
        return _res;
    }
    void postorderEx(Node* root){
        if(!root)
            return;
        //std::cout<<" v="<val<children.size();i++){
            postorderEx(root->children[i]);
        }
        _res.push_back(root->val);
    }
    
    vector _res;
};


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注