Build Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:
The root is the maximum number in the array.
The left subtree is the maximum tree constructed from left part subarray divided by the maximum number.
The right subtree is the maximum tree constructed from right part subarray divided by the maximum number.
Construct the maximum tree by the given array and output the root node of this tree.
Example
Note
Divide and Conquer
To build the tree based on recursively finding the the max in left and right divided parts.
Mind the start and end, which suggests the ending conditions for the helper function.
Code
Last updated