Java using HashMap
\tclass Solution {\n\t\t\tint n = 0;\n\t\t\tMap hm = new HashMap<>();\n\t\t\tpublic TreeNode buildTree(int[] inorder, int[] postorder) {\n\t\t\t\tn = inorder.le
\tclass Solution {\n\t\t\tint n = 0;\n\t\t\tMap<Integer, Integer> hm = new HashMap<>();\n\t\t\tpublic TreeNode buildTree(int[] inorder, int[] postorder) {\n\t\t\t\tn = inorder.length-1;\n\t\t\t\tfor (int i=0; i< inorder.length; i++){\n\t\t\t\t\thm.put(inorder[i], i);   \n\t\t\t\t}\n\t\t\t\treturn buildTree(postorder, inorder, 0, inorder.length-1);\n\n\t\t\t}\n\n\t\t\tprivate TreeNode buildTree(int[] postorder, int[] inorder, int start, int end) {\n\t\t\t\tif (start > end) return null;\n\n\t\t\t\tTreeNode root = new TreeNode(postorder[n]);\n\t\t\t\tn--;\n\n\t\t\t\tif (start == end) return root;\n\n\t\t\t\tint index = hm.get(root.val);\n\n\t\t\t\troot.right = buildTree(postorder, inorder, index + 1, end);\n\t\t\t\troot.left = buildTree(postorder, inorder, start, index - 1);\n\n\t\t\t\treturn root;\n\n\t\t\t}\n\t}
[]