# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# 返回构造的TreeNode根节点
def reConstructBinaryTree(self, pre, tin):
# write code here
if len(pre)==0 or len(tin)==0:return None
root=pre[0]
flag=tin.index(pre[0])
n=TreeNode(root)
n.left=self.reConstructBinaryTree(pre[1:1+flag],tin[:flag])
n.right=self.reConstructBinaryTree(pre[flag+1:],tin[flag+1:])
return n