zoukankan      html  css  js  c++  java
  • Leetcode 654. Maximum Binary Tree

    # 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
            
  • 相关阅读:
    XML 编码
    XML CDATA
    XML 命名空间
    XML 解析器
    XML XMLHttpRequest 对象
    XML 和CSS
    XML 验证
    XML 属性
    XML 元素
    XML 语法规则
  • 原文地址:https://www.cnblogs.com/zywscq/p/10644365.html
Copyright © 2011-2022 走看看