17. Letter Combinations of a Pho
作者:
夜皇雪 | 来源:发表于
2016-11-27 04:09 被阅读0次public class Solution {
public List<String> letterCombinations(String digits) {
LinkedList<String> ans = new LinkedList<String>();
if (digits.length()==0) return ans;
String[] mapping = new String[] {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
ans.add("");
for(int i =0; i<digits.length();i++){
int x = Character.getNumericValue(digits.charAt(i));
while(ans.peek().length()==i){
String t = ans.remove();
for(char s : mapping[x].toCharArray())
ans.add(t+s);
}
}
return ans;
}
}
本文标题:17. Letter Combinations of a Pho
本文链接:https://www.haomeiwen.com/subject/bnngpttx.html
网友评论