标签:io for ar new har ad 递归 public
这是一个循环操作,如果重数太多,只能递归搜索,不满足条件return 或者else,刚才出错了
public class Solution {
private String letters[] = {"","","abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
private List<String> ret=new ArrayList<String>();
public List<String> letterCombinations(String digits) {
if(digits.length()==0)
{
ret.add("");
return ret;
}
List<String> list=new ArrayList<String>();
char c[]=digits.toCharArray();
leeter(0,c,"");
return ret;
}
public void leeter(int lev,char c[],String s)
{
if(lev==c.length){ ret.add(new String(s));return;}
for(int i=0;i<letters[c[lev]-‘0‘].length();i++)
{
char c1=letters[c[lev]-‘0‘].charAt(i);
leeter(lev+1,c,s+c1);
}
}
}
Letter Combinations of a Phone Number,布布扣,bubuko.com
Letter Combinations of a Phone Number
标签:io for ar new har ad 递归 public
原文地址:http://www.cnblogs.com/hansongjiang/p/3873924.html