Maximum Binary Tree II LeetCode solution in JavaScript
1/**2* @param {TreeNode} root3* @param {number} val4* @return {TreeNode}5*/6var insertIntoMaxTree = function (root, val) {7// get new node8var node = new TreeNode(val);910// no root11if (!root) {12return node;13}1415// upward derivation if val larger then root16if (val > root.val) {17return (node.left = root), node;18}1920// downward derivation21root.right = insertIntoMaxTree(root.right, val);2223// root construct24return root;25};