leetcode: 传送门
function postOrderTraversal(root) {
let res = [];
let stack = [];
if (root == null) {
return res;
}
stack.push(root);
while (stack.length) {
let node = stack.pop();
res.unshift(node.val);
if (root.left) {
stack.push(node.left);
}
if (root.right) {
stack.push(node.right);
}
}
return res;
}