标签:letters lis com 电话 character 电话号码 problems index git
class Solution {
private String letters[] = {" ", "", "abc", "def", "ghi", "jkl", "mno",
"pqrs", "tuv", "wxyz"};
private List<String> ans;
public List<String> letterCombinations(String digits) {
ans = new ArrayList<String>();
if (digits.equals("")) return ans;
help(digits, 0, "");
return ans;
}
private void help(String digits, int index, String s) {
if (index == digits.length()) {
ans.add(s);
return ;
}
Character c = digits.charAt(index);
String l = letters[c - ‘0‘];
for (int i = 0; i < l.length(); ++i) {
help(digits, index + 1, s + l.charAt(i));
}
}
}
标签:letters lis com 电话 character 电话号码 problems index git
原文地址:https://www.cnblogs.com/clown9804/p/13121573.html