码迷,mamicode.com
首页 > 其他好文 > 详细

type area

时间:2019-11-11 12:23:05      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:ini   turn   build   efi   dtree   str   div   return   col   

1.use preorder inorder postorder to construct the 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 buildTree(self, preorder, inorder):
    #     """
    #     :type preorder: List[int]
    #     :type inorder: List[int]
    #     :rtype: TreeNode
    #     """
    def buildTree(self,preorder,inorder):
            if not inorder or not preorder:
                return None
            root=TreeNode(preorder[0])
            index=inorder.index(preorder[0])
            root.left=self.buildTree(preorder[1:index+1],inorder[:index])
            root.right=self.buildTree(preorder[index+1:],inorder[index+1:])
            return root
    
        

 

type area

标签:ini   turn   build   efi   dtree   str   div   return   col   

原文地址:https://www.cnblogs.com/Marigolci/p/11834036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!