91: Maximum binary tree
Given an array of integers without duplicates. Create and return a maximum binary tree by following rules:
- the
rootis themaximum numberin thearray- the
left subtreeis themaximum treecreated fromleft partsubarray divided by the maximum number- the
right subtreeis themaximum treecreated fromright partsubarray divided by the maximum number
Example 1
Input: [1, 3, 2]
Output: 3
/ \
1 2
Example 2
Input: [3, 2, 1]
Output: 3
\
2
\
1