C++ O(n) DFS solution beath 91% submissions
Example\n\n           13\n         /    \\n        2      3\n       / \    /\n      5   6  7\n            / \\n           8   9\n                \\n            
Example\n\n           13\n         /    \\\n        2      3\n       / \\    /\n      5   6  7\n            / \\\n           8   9\n                \\\n                10\n                /\n              12\n\n    5,  2,  6,  13,  8,  7,  9,  12,  10,  3\n    ---left--- root  ---------right---------\n    \n    5,  6,  2,  8,  12,  10,  9,  7,  3,  13\n    ---left---\t---------right---------- root \n\nCode\n\n    class Solution {\n    private:\n            unordered_map<int, int> inm; // inorder map [inorder[i], i]\n    \n    public:\n        TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {\n            int n = inorder.size(), i = 0;\n            for(auto val: inorder) inm[val] = i++; // build inm for dfs \n            \n            return dfs(inorder, 0, n - 1, postorder, 0, n - 1);\n        }\n        \n        TreeNode* dfs(vector<int>& inorder, int ileft, int iright, vector<int>& postorder, int pleft, int pright) {\n            if(ileft > iright) return nullptr;\n            \n            int val = postorder[pright]; // root value\n            TreeNode *root = new TreeNode(val);\n            if(ileft == iright) return root;\n            \n            int iroot = inm[val];\n            int nleft = iroot - ileft; // length of left subtree\n            root->right = dfs(inorder, iroot + 1, iright, postorder, pleft + nleft, pright - 1);\n            root->left = dfs(inorder, ileft, iroot - 1, postorder, pleft, pleft + nleft - 1);\n            \n            return root;\n        }\n    };
['C++']