Write a function to generate the generalized abbreviations of a word.
Input: "word"
Output: ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]
class Solution {
public List<String> generateAbbreviations(String word) {
List<String> res = new ArrayList<>();
helper(word, res, "", 0, 0);
return res;
}
private void helper(String word, List<String> res, String curr,
int pos, int count) {
if (pos == word.length()) {
res.add(count > 0 ? curr + count : curr);
return;
}
helper(word, res, curr, pos + 1, count + 1);
helper(word, res, curr + (count > 0 ? count : "") + word.charAt(pos), pos + 1, 0);
}
}