Easy JAVA solution with simple explanation
\nIntuition:\n\n- Postorder traversal: Left, Right, Root.\n- Inorder traversal: Left, Root, Right.\n- We can use the postorder traversal to determine the root o
\n**Intuition:**\n\n- **Postorder traversal:** Left, Right, Root.\n- **Inorder traversal:** Left, Root, Right.\n- We can use the postorder traversal to determine the root of the tree.\n- Then, we can use the inorder traversal to find the division between the left and right subtrees.\n- We can recursively build the left and right subtrees using the same approach.\n\n**Approach:**\n\n1. **Create a HashMap:** Store the indices of each element in the inorder traversal for quick lookup.\n2. **Build the subtree:**\n   - Base case: If `inStart > inEnd` or `postStart > postEnd`, return `null`.\n   - **Root:** The root is always the last element in the postorder traversal.\n   - **Left subtree:** Find the index of the root in the inorder traversal. The elements to the left of it form the left subtree.\n   - **Right subtree:** The elements to the right of the root in the inorder traversal form the right subtree.\n   - Recursively build the left and right subtrees.\n\n**Complexity:**\n\n- **Time complexity:** `O(n)` where `n` is the number of nodes in the tree.\n- **Space complexity:** `O(n)` for the HashMap and the recursion stack.\n\n\n\n\n# Code\n```java []\n\nclass Solution {\n    public TreeNode buildTree(int[] inorder, int[] postorder) {\n        HashMap<Integer, Integer> map = new HashMap<>();\n        for (int i = 0; i < inorder.length; i++) {\n            map.put(inorder[i], i);\n        }\n        return fun(inorder, 0, inorder.length - 1, postorder, 0, postorder.length - 1, map);\n    }\n\n    public TreeNode fun(int[] inOrder, int inStart, int inEnd, int[] postOrder, int postStart, int postEnd,\n            HashMap<Integer, Integer> map) {\n        if (inStart > inEnd || postStart > postEnd) {\n            return null;\n        }\n        TreeNode root = new TreeNode(postOrder[postEnd]);\n        int inIndex = map.get(root.val);\n        int leftTreeSize = inIndex - inStart;\n\n        root.left = fun(inOrder, inStart, inIndex - 1, postOrder, postStart, postStart + leftTreeSize - 1, map);\n        root.right = fun(inOrder, inIndex + 1, inEnd, postOrder, postStart + leftTreeSize, postEnd - 1, map);\n        return root;\n    }\n}\n\n```
['Array', 'Hash Table', 'Divide and Conquer', 'Tree', 'Binary Tree', 'Java']