https://leetcode.com/problems/binary-tree-postorder-traversal/
Solution 1
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
var postorderTraversal = function (root) {
let result = [];
traversalHelper(root, result);
return result;
};
const traversalHelper = (root, result) => {
if (root === null) {
return;
}
result.unshift(root.val);
traversalHelper(root.right, result);
traversalHelper(root.left, result);
};