publicclassSolution{publicList<String>letterCombinations(Stringdigits){LinkedList<String>ret=newLinkedList<String>();String[]mapping=newString[]{"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};if(digits.length()==0)returnret;ret.add("");for(inti=0;i<digits.length();i++){// x 是在mapping中的索引intx=Character.getNumericValue(digits.charAt(i));// ret 中peek 长度如果和i相等,则制造下一个digitwhile(ret.peek().length()==i){// remove peek elementStringtop=ret.remove();for(chars:mapping[x].toCharArray())ret.add(top+s);}}returnret;}}