followed the idea but manipulating indices in [low_index_inclusive, high_index_exclusive) way makes me a little bit happier...

class Solution { private int[] inorder, postorder; private Map<Integer, Integer> indicesMap; public TreeNode buildTree(int[] inorder, int[] postorder) { if (inorder == null || postorder == null || inorder.length != postorder.length) { return null; } this.inorder = inorder; this.postorder = postorder; indicesMap = new HashMap<>(); for (int i = 0; i < inorder.length; i++) { indicesMap.put(inorder[i], i); } return build(0, inorder.length, 0, postorder.length); } private TreeNode build(int inLow, int inHigh, int postLow, int postHigh) { if (inLow == inHigh || postLow == postHigh) { return null; } TreeNode root = new TreeNode(postorder[postHigh - 1]); int rootIndex = indicesMap.get(root.val), postThreshold = postLow + rootIndex - inLow; root.left = build(inLow, rootIndex, postLow, postThreshold); root.right = build(rootIndex + 1, inHigh, postThreshold, postHigh - 1); return root; } }Construct Binary Tree from Inorder and Postorder Traversal