本来打算用subString但是用成了sunString,我就先不改了,大家觉得别扭的可以改一下
public List<String> letterCombinations(String digits) {
char[][] phone = {{'a','b','c'}, {'d','e','f'},{'g','h','i'},
{'j','k','l'},{'m','n','o'},{'p','q','r','s'},
{'t','u','v'},{'w','x','y','z'}};
if(digits == null || digits.equals("")){
return new ArrayList<>();
}
Integer integer = Integer.valueOf(digits.substring(0,1));
char[] phoneNum = phone[integer-2];
List<String> result = new ArrayList<>();
List<String> sunString = this.letterCombinations(digits.substring(1));
for (int i = 0; i < phoneNum.length; i++) {
char num = phoneNum[i];
// System.out.println(sunString);
// System.out.println(String.valueOf(num));
List<String> temp = new ArrayList<>();
if(sunString == null || sunString.size() ==0){
temp.add(String.valueOf(String.valueOf(num)));
}else {
for (String str : sunString) {
temp.add(str + String.valueOf(num));
}
}
// System.out.println(temp);
result.addAll(temp);
}
return result;
}