public TreeNode builder(HashMap<Integer, Integer> map, int[] preorder, int begin, int end, int inBegin, int inEnd) {
        if (begin > end)
            return null;
        int val = preorder[begin];
        TreeNode root = new TreeNode(val);
        int index = map.get(val);
        int left_size = index - inBegin;
        int right_size = inEnd - index;
        root.left = builder(map, preorder, begin + 1, begin + left_size, inBegin, index - 1);
        root.right = builder(map, preorder, begin + left_size + 1, end, index + 1, inEnd);
        return root;
    }