you are given an integer array nums with no duplicates. A
maximum binary tree can be built recursively from nums using the
following algorithm: Create a root node whose value is the maximum
value in nums. Recursively build the left subtree on the subarray
prefix to the left of the maximum value. Recursively build the
right subtree on the subarray suffix to the right of the maximum
value. Return the maximum binary tree built from nums. /** *
Definition for a binary tree node. * struct TreeNode { * int val; *
TreeNode *left; * TreeNode *right; * TreeNode() : val(0),
left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x),
left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left,
TreeNode *right) : val(x), left(left), right(right) {} * }; */
class Solution { public: TreeNode*
constructMaximumBinaryTree(vector& nums) { } };
you are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using t
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
you are given an integer array nums with no duplicates. A maximum binary tree can be built recursively from nums using t
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!