public TreeNode fromPostInOrderBuilder(int[] postorder, int[] inorder, int poststart, int instart, int length) {
        if (length == 0) return null; //should raise exception if length < 0

        int topVal = postorder[poststart+length-1];
        int topInIndex = instart;
        for (int inIndexEnd=instart+length; topInIndex<inIndexEnd; topInIndex++)
            if (inorder[topInIndex] == topVal) break;
        int leftLength = topInIndex - instart;
        int rightLength = length -leftLength - 1;

        TreeNode top = new TreeNode(topVal);
        top.left = fromPostInOrderBuilder(postorder,inorder,poststart,instart,leftLength);
        top.right = fromPostInOrderBuilder(postorder,inorder,poststart+leftLength,instart+leftLength+1, rightLength);

        return top;
    }