题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3ffe0d0b0092b67087c7e82030798e43.png)
方法思路
class Solution {
public TreeNode constructMaximumBinaryTree(int[] nums) {
TreeNode root = constructMBT_Helper(nums, 0, nums.length - 1);
return root;
}
public TreeNode constructMBT_Helper(int[] nums, int start, int end){
if(start > end) return null;
if(start == end) return new TreeNode(nums[start]);
int index = findMaxIndex(nums, start, end);
TreeNode root = new TreeNode(nums[index]);
root.left = constructMBT_Helper(nums, start, index - 1);
root.right = constructMBT_Helper(nums, index + 1, end);
return root;
}
public int findMaxIndex(int[] nums, int start, int end){
int index = start, max = nums[start];
for(int i = start; i <= end; i++){
if(max < nums[i]){
max = nums[i];
index = i;
}
}
return index;
}
}