leetcode590+多叉树的后序遍历,递归

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 res;
    vector postorder(Node* root) {
        if(root!=NULL){
            for(auto n:root->children){
                postorder(n);
            }
            res.push_back(root->val);
        }
        return res;
    }
};

 

你可能感兴趣的:(Leetcode)