用递归法解决

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def constructMaximumBinaryTree(self, nums: List[int]) -> Optional[TreeNode]:
        if not nums:
            return None
        
        root_val = max(nums)
        root = TreeNode(root_val)
        
        separate = nums.index(root_val)
        root.left = self.constructMaximumBinaryTree(nums[:separate])
        root.right = self.constructMaximumBinaryTree(nums[separate+1:])
        
        return root

654. Maximum Binary Tree刷题笔记_数据结构