Letter Combinations of a Phone Number

这是一个循环操作,如果重数太多,只能递归搜索,不满足条件return 或者else,刚才出错了

 

public class Solution {
private String letters[] = {"","","abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
private List ret=new ArrayList();
public List letterCombinations(String digits) {
if(digits.length()==0)
{
ret.add("");
return ret;

}

List list=new ArrayList();

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 {
char c1=letters[c[lev]-'0'].charAt(i);
leeter(lev+1,c,s+c1);
}

}
}

转载于:https://www.cnblogs.com/hansongjiang/p/3873924.html

你可能感兴趣的:(Letter Combinations of a Phone Number)