题目描述
blablabla
样例
blablabla
算法1
Java 代码
class Solution {
Map<Character, String> phone = new HashMap<>(){{
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> res = new ArrayList<>();
public List<String> letterCombinations(String digits) {
if(digits == null || digits.length() == 0) return res;
dfs(digits, 0, new String());
return res;
}
private void dfs(String digits, int index, String s){
if(index == digits.length()){
res.add(s);
return;
}
String letter = phone.get(digits.charAt(index));
for(int i = 0; i < letter.length(); i++){
String str = letter.substring(i, i + 1);
dfs(digits, index + 1, s+str);
}
}
}