class Solution {
Map<String, String> phone = new HashMap<String, String>() {{
put("2", "abc");
put("3", "def");
put("4", "ghi");
put("5", "jkl");
put("6", "mno");
put("7", "pqrs");
put("8", "tuv");
put("9", "wxyz");
}};
List<String> output = new ArrayList<String>();
private void backtack(String combination, String next_digit) {
if (next_digit.length() == 0) {
output.add(combination);
} else {
// 获取要组合的字母组合
String letters = phone.get(next_digit.substring(0, 1));
for (int i = 0; i < letters.length(); i++) {
// 递归组合
backtack(combination + letters.substring(i, i + 1), next_digit.substring(1));
}
}
}
public List<String> letterCombinations(String digits) {
if (digits.length() > 0) {
backtack("", digits);
}
return output;
}
}