C++ Solution
Complexity\n- Time complexity: O(n*log(n))\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\n public:\n  TreeNode* buildTree(vector<int>& inorder, vect
# Complexity\n- Time complexity: $$O(n*log(n))$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\n public:\n  TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {\n    unordered_map<int, int> inToIndex;\n\n    for (int i = 0; i < inorder.size(); ++i)\n      inToIndex[inorder[i]] = i;\n\n    return build(inorder, 0, inorder.size() - 1, postorder, 0,\n                 postorder.size() - 1, inToIndex);\n  }\n\n private:\n  TreeNode* build(const vector<int>& inorder, int inStart, int inEnd,\n                  const vector<int>& postorder, int postStart, int postEnd,\n                  const unordered_map<int, int>& inToIndex) {\n    if (inStart > inEnd)\n      return nullptr;\n\n    const int rootVal = postorder[postEnd];\n    const int rootInIndex = inToIndex.at(rootVal);\n    const int leftSize = rootInIndex - inStart;\n\n    TreeNode* root = new TreeNode(rootVal);\n    root->left = build(inorder, inStart, rootInIndex - 1, postorder, postStart,\n                       postStart + leftSize - 1, inToIndex);\n    root->right = build(inorder, rootInIndex + 1, inEnd, postorder,\n                        postStart + leftSize, postEnd - 1, inToIndex);\n    return root;\n  }\n};\n\n```
['Tree', 'Binary Tree', 'C++']