def ToPreOrder(Postorder,Inorder):
length = len(Postorder)
if length == 0:
return 0
root = Postorder[length-1] //根节点
for i in range(length): //找到中序遍历中根节点的位序
if root == Inorder[i]:
break
print(root,end="")
ToPreOrder(Postorder[0:i],Inorder[0:i]) //递归,传入左子树的后序和中序遍历序列
ToPreOrder(Postorder[i:length-1],Inorder[i+1:length]) //递归,传入右子树的后序和中序遍历序列
ToPreOrder("672541","627154")
print("\n")