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