def reConstructBinaryTree(self, pre, tin):
if not pre:
return None
cur_val = pre.pop(0)
root = TreeNode(cur_val)
index = tin.index(cur_val)
root.left = self.reConstructBinaryTree(pre[:index], tin[:index])
root.right = self.reConstructBinaryTree(pre[index:], tin[index+1:])
return root就是···递归吧。



京公网安备 11010502036488号