电话号码的字母组合
来源:互联网 发布:java程序员高清壁纸 编辑:程序博客网 时间:2024/04/30 10:09
要求:给定一个数字字符串,返回数字可能表示的所有可能的字母组合。下面给出了数字到字母的映射(就像在电话按钮上)。
输入:数字串“23”
输入:数字串“23”
输出: [“ad”,“ae”,“af”,“bd”,“be”,“bf”,“cd”,“ce”,“cf”]。
代码如下:
public static List<String> letterCombinations(String digits) {
List<String> res = new ArrayList<String>();
if (digits == null || digits.length() == 0) return res;
Map<Character,String> map=new HashMap<>();
map.put('0', "");
map.put('1', "");
map.put('2', "abc");
map.put('3', "def");
map.put('4', "ghi");
map.put('5', "jkl");
map.put('6', "mno");
map.put('7', "pqrs");
map.put('8', "tuv");
map.put('9', "wxyz");
StringBuilder[] str=new StringBuilder[digits.length()];
for(int i=0;i<digits.length();i++)
{
str[i]=new StringBuilder();
str[i].append(map.get(digits.charAt(i)));
}
res.add("");
for(int i=0;i<digits.length();i++)
{
List<String> newRes = new ArrayList<String>();
for (String value : res){
for(int j=0;j<str[i].length();j++)
{
newRes.add(value+str[i].charAt(j));
}
}
res=newRes;
}
return res;
}
- 电话号码的字母组合
- 电话号码的字母组合
- 电话号码的字母组合
- 电话号码的字母组合
- 电话号码的字母组合
- LintCode: 电话号码的字母组合
- lintcode,电话号码的字母组合
- lintcode -- 电话号码的字母组合
- 电话号码的字母组合-lintcode
- LintCode 电话号码的字母组合
- lintcode---电话号码的字母组合
- 电话号码的字母组合-LintCode
- lintcode-电话号码的字母组合-425
- LeetCode 17 Letter Combinations of a Phone Number(电话号码的字母组合)
- 425.Letter Combinations of a Phone Number-电话号码的字母组合(中等题)
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
- 17:Letter Combinations of a Phone Number(字母组合的电话号码)
- Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】
- centos下快速重置mysql密码
- MySQL日期函数
- JspContext、pageContext等的区别
- JVM参数配置大全
- hibernate学习笔记第二天(1)
- 电话号码的字母组合
- 方法反射出现异常
- Ubuntu 部署 Flask + WSGI + Nginx 详解
- NDK-JNI交互处理
- mysql 自定义排序规则
- 【观察者】设计模式
- WORD里面可以使表格从中间断开或往下移动一行的快捷键(不需要使用十字架移动表格)
- Android官方多媒体API Mediacodec翻译
- Hibernate各种查询(下)