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;
}
};
网友评论