图片说明

/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function reConstructBinaryTree(pre, vin)
{
    // write code here
    if(pre.length == 0 || vin.length ==0) return null
    var root = new TreeNode(pre[0])
    var index = vin.indexOf(pre[0])
    root.left = reConstructBinaryTree(pre.slice(1,index+1),vin.slice(0,index))
    root.right = reConstructBinaryTree(pre.slice(index+1),vin.slice(index+1))
    return root
}