var buildTree = function(inorder, postorder) {
if(inorder.length === 0) return null;
let root_val = postorder[postorder.length-1],
root_index_inorder = inorder.indexOf(root_val),
root = new TreeNode(root_val);
let inorder_left = inorder.slice(0,root_index_inorder),
inorder_right = inorder.slice(root_index_inorder+1),
postorder_left = postorder.slice(0,inorder_left.length),
postorder_right = postorder.slice(inorder_left.length,-1);
root.left = buildTree(inorder_left,postorder_left);
root.right = buildTree(inorder_right,postorder_right);
return root;
};