美文网首页
590. N-ary Tree Postorder Traver

590. N-ary Tree Postorder Traver

作者: Jesson3264 | 来源:发表于2018-11-20 19:35 被阅读0次
    class Solution {
    public:
        vector<int> postorder(Node* root) {
            vector<int> ret;
            if (!root) 
                return ret;
            stack<Node *> s;
            s.push(root);
            Node *cur; 
            while (!s.empty())
            {
                cur = s.top();
                s.pop();
                ret.insert(ret.begin(), cur->val);
                for (int i = 0; i < cur->children.size(); ++i)
                {
                    if (cur->children[i])
                        s.push(cur->children[i]);
                }
            }
            
            return ret;
        }
    };
    

    相关文章

      网友评论

          本文标题:590. N-ary Tree Postorder Traver

          本文链接:https://www.haomeiwen.com/subject/xbzxqqtx.html