class Solution:
def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode:
if len(inorder)==0: return None
root = TreeNode(postorder[-1])
root_in = inorder.index(root.val)
root.left = self.buildTree(inorder[:root_in],postorder[:root_in])
root.right = self.buildTree(inorder[root_in+1:],postorder[root_in:-1])
return root
106. 从中序与后序遍历序列构造二叉树
最新推荐文章于 2024-07-27 17:45:51 发布