Maximum Binary Tree LeetCode solution in Python
1class Solution:2def constructMaximumBinaryTree(self, nums: List[int]) -> Optional[TreeNode]:3if not nums:4return None5m = max(nums)6idx = nums.index(m)7root = TreeNode(m)8root.left = self.constructMaximumBinaryTree(nums[:idx])9root.right = self.constructMaximumBinaryTree(nums[idx + 1 :])10return root