C++ Simple and Clean Recursive Solution, With Explanation, No Map
Explanation:\nWhen we do an inorder traversal, we have the left subtree, then somewhere in the middle the root, then the right subtree.\nWhen we do postorder tr
**Explanation:**\nWhen we do an inorder traversal, we have the left subtree, then somewhere in the middle the root, then the right subtree.\nWhen we do postorder traversal, we have the root at the end.\n\nSo we have `m_curr` to go from the end of `m_postorder` - this will be the root at each iteration.\nNow, we have the value of the root, we try to find that value in `m_inorder`.\nOnce we found the index of the root in `m_inorder`, we know that the subarray in the left belongs to the left subtree and the right subarray is the right subtree.\nSo all we need to do is create the current root from that value and send to a recursive call with the right indices.\nWe also decrease `m_curr` to have the next subtree\'s root.\n```\nclass Solution {\npublic:\n    TreeNode* rec(int l, int r) {\n        if (l > r) return NULL;\n        \n        int i = 0;\n        while (m_inorder[i] != m_postorder[m_curr]) {\n            i++;\n        }\n        \n        m_curr--;\n        TreeNode* node = new TreeNode(m_inorder[i]);\n        node->right = rec(i+1, r);\n        node->left = rec(l, i-1);\n        return node;\n        \n    }\n    \n    TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {\n        m_postorder = postorder, m_inorder = inorder, m_curr = inorder.size()-1;\n        return rec(0, postorder.size()-1);\n    }\n    \nprivate:\n    int m_curr;\n    vector<int> m_postorder, m_inorder;\n};\n```\n**Like it? please upvote!**
['C']