Very short solution without extra space.

TreeNode* buildTree(vector<int> inorder, vector<int> postorder) { if(inorder.empty()||postorder.empty()) return NULL; int i = find(inorder.begin(), inorder.end(), postorder.back()) - inorder.begin(); TreeNode* root = new TreeNode(postorder.back()); root->left = buildTree( vector<int>(inorder.begin(), inorder.begin()+i), vector<int>(postorder.begin(), postorder.begin()+i) ); root->right= buildTree( vector<int>(inorder.begin()+i+1, inorder.end()), vector<int>(postorder.begin()+i, postorder.end()-1) ); return root; }Construct Binary Tree from Inorder and Postorder Traversal