Binary Tree Pruning


@mrincodi did a great job simplifying this. I've added comments in my javascript version:
var pruneTree = function(root) { if (!root) return null // recurse as deep as you can until you hit a leaf root.left = pruneTree(root.left) root.right = pruneTree(root.right) // we only keep leaf nodes if they contain a 1 const isLeaf = !root.left && !root.right if (isLeaf && root.val !== 1) return null return root };