# -*- 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 not pre or not tin:
return None
root = TreeNode(pre.pop(0))
root_local = tin.index(root.val)
root.left = self.reConstructBinaryTree(pre[:root_local+1], tin[:root_local])
root.right = self.reConstructBinaryTree(pre[root_local:], tin[root_local+1:])
return root