-
-
Save yschen25/4eb5e87b1b8f85ca84a44f606ebaa9f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const postorder = function (node, acc = []) { | |
if (!node) return acc; | |
const { value, left, right } = node; | |
postorder(left, acc); | |
postorder(right, acc); | |
acc.push(value); | |
return acc; | |
}; | |
console.log(postorder(tree)); // [6, 7, 3, 4, 1, 8, 9, 5, 2, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment