var postorder = function(root) {
const result = []
const stack = [root];
while (stack.length) {
const curr = stack.pop();
if (!curr) continue;
result.push(curr.val);
stack.push(...curr.children);
console.log(stack);
}
console.log(result);
return result.reverse();
};
var postorder = function(root) {
const res = [];
traverse(root);
return res;
function traverse(node) {
if (!node) return;
for(child of node.children) {
traverse(child);
}
res.push(node.val);
}
};