/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function reConstructBinaryTree(pre, vin) { if (pre.length === 0 ) { return null } let root = pre[0] let rootNode = new TreeNode(root) let idx = vin.findIndex((item) => item === root) rootNode.left = reConstructBinaryTree(pre.slice(1, idx + 1), vin.slice(0, idx)) rootNode.right = reConstructBinaryTree(pre.splice(idx + 1), vin.slice(idx + 1)) return rootNode }