标签: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
标签:ini turn build efi dtree str div return col
原文地址:https://www.cnblogs.com/Marigolci/p/11834036.html