public class Solution {
String[] keybd ={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
// http://www.cnblogs.com/springfor/p/3879829.html
public ArrayList<String> letterCombinations(String digits) {
ArrayList<String> res = new ArrayList<String>();
if(digits.length()<1) return res;
StringBuilder item = new StringBuilder();
dfs(digits, item, res, 0);
return res;
}
public void dfs(String digits, StringBuilder item, ArrayList<String> res, int start){
if(start== digits.length()) {
res.add(item.toString()); // 不是 new StringBuilder (item)
return;
}
int num = digits.charAt(start)-'0';
for(int i=0;i<keybd[num].length();i++){
item.append(keybd[num].charAt(i));
dfs(digits, item, res, start+1);
item.deleteCharAt(item.length()-1);
}
}
}
String[] keybd ={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
// http://www.cnblogs.com/springfor/p/3879829.html
public ArrayList<String> letterCombinations(String digits) {
ArrayList<String> res = new ArrayList<String>();
if(digits.length()<1) return res;
StringBuilder item = new StringBuilder();
dfs(digits, item, res, 0);
return res;
}
public void dfs(String digits, StringBuilder item, ArrayList<String> res, int start){
if(start== digits.length()) {
res.add(item.toString()); // 不是 new StringBuilder (item)
return;
}
int num = digits.charAt(start)-'0';
for(int i=0;i<keybd[num].length();i++){
item.append(keybd[num].charAt(i));
dfs(digits, item, res, start+1);
item.deleteCharAt(item.length()-1);
}
}
}