树的后序遍历。

class Solution {
public:
    vector<Node> Tree;
    void postTree(Node node)
    {
        for (auto n : node.children)
        {
            Node node;
            node = Node(n->val, n->children);
            postTree(node);
        }
        Tree.push_back(Node(node.val, node.children));
    }

    vector<int> postorder(Node* root) {
        vector<int> V;
        if (root != NULL)
        {
            postTree(*root);
        }
        for (auto n : Tree)
        {
            V.push_back(n.val);
        }
        return V;
    }
};

 

posted on 2018-09-26 00:27  Sempron2800+  阅读(83)  评论(0编辑  收藏  举报