# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def constructMaximumBinaryTree(self, nums): """ :type nums: List[int] :rtype: TreeNode """ if not nums: return None ret = TreeNode(max(nums)) i = nums.index(ret.val) ret.left = self.constructMaximumBinaryTree(nums[:i]) ret.right = self.constructMaximumBinaryTree(nums[i + 1:] if len(nums) > i + 1 else None) return ret
Leetcode 654. Maximum Binary Tree
猜你喜欢
转载自www.cnblogs.com/zywscq/p/10644365.html
今日推荐
周排行