public class Solution {
public List<String> letterCombinations(String digits) {
List<String> ls = new ArrayList<>();
ls.add("");
if (digits.length() < 1)
return ls;
String[] arr = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
List<String> tmp = new ArrayList<String>();
String s0 = arr[digits.charAt(0)-'0'];
for(int s=0; s<s0.length(); s++){
tmp.add(""+s0.charAt(s));
}
for(int i=1; i<digits.length(); i++){
String si = arr[digits.charAt(i) - '0'];
tmp = letterCombinationHelper(tmp, si);
}
return tmp;
}
public List<String> letterCombinationHelper(List<String> ls, String s) {
List<String> l = new ArrayList<>();
for(int i=0; i<ls.size(); i++){
for(int j=0; j<s.length(); j++){
l.add(ls.get(i)+s.charAt(j));
}
}
return l;
}
}
-------------------------------
HINT:
沉着,思路清晰;然后使用递归,跟着知觉~~~~ 没有特别的函数的使用,主要是思路清晰
===================
Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.