Title: #776 - Split BST - LeetCode JavaScript Solutions
Open Graph Title: #776 - Split BST - LeetCode JavaScript Solutions
X Title: #776 - Split BST - LeetCode JavaScript Solutions
Description: Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that ...
Open Graph Description: Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that ...
X Description: Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/split-bst
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/split-bst","name":"#776 - Split BST - LeetCode JavaScript Solutions","description":"Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @param {number} target\n * @return {TreeNode[]}\n */\nvar splitBST = function(root, target) {\n if (!root) return [null, null];\n\n if (root.val <= target) {\n const [smaller, larger] = splitBST(root.right, target);\n root.right = smaller;\n return [root, larger];\n } else {\n const [smaller, larger] = splitBST(root.left, target);\n root.left = larger;\n return [smaller, root];\n }\n};","keywords":"LeetCode 776, #776 - Split BST, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/split-bst |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/split-bst/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0776-split-bst.js |
| Tree | https://leetcodejavascript.com/tags/tree |
| Binary Tree | https://leetcodejavascript.com/tags/binary-tree |
| Recursion | https://leetcodejavascript.com/tags/recursion |
| Binary Search Tree | https://leetcodejavascript.com/tags/binary-search-tree |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow