首页 > 代码库 > Letter Combinations of a Phone Number

Letter Combinations of a Phone Number

这是一个循环操作,如果重数太多,只能递归搜索,不满足条件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);
}

}
}