Title: #654 - Maximum Binary Tree - LeetCode JavaScript Solutions
Open Graph Title: #654 - Maximum Binary Tree - LeetCode JavaScript Solutions
X Title: #654 - Maximum Binary Tree - LeetCode JavaScript Solutions
Description: You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorit...
Open Graph Description: You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorit...
X Description: You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorit...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/maximum-binary-tree
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/maximum-binary-tree","name":"#654 - Maximum Binary Tree - LeetCode JavaScript Solutions","description":"You are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using the following algorit...","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 {number[]} nums\n * @return {TreeNode}\n */\nvar constructMaximumBinaryTree = function(nums) {\n if (!nums.length) return null;\n\n const max = Math.max(...nums);\n const index = nums.indexOf(max);\n const head = new TreeNode(max);\n\n head.left = constructMaximumBinaryTree(nums.slice(0, index));\n head.right = constructMaximumBinaryTree(nums.slice(index + 1));\n\n return head;\n};","keywords":"LeetCode 654, #654 - Maximum Binary Tree, 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/maximum-binary-tree |
| 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/maximum-binary-tree/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0654-maximum-binary-tree.js |
| Array | https://leetcodejavascript.com/tags/array |
| Tree | https://leetcodejavascript.com/tags/tree |
| Binary Tree | https://leetcodejavascript.com/tags/binary-tree |
| Stack | https://leetcodejavascript.com/tags/stack |
| Monotonic Stack | https://leetcodejavascript.com/tags/monotonic-stack |
| Divide and Conquer | https://leetcodejavascript.com/tags/divide-and-conquer |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow