LeetCode 17 Letter Combinations of a Phone Number
来源:互联网 发布:ucloud云计算 2016 09 编辑:程序博客网 时间:2024/06/10 11:51
Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
Input:Digit string “23”
Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
解决
class Solution { static String[][] numbers = new String[][] { {""}, {""}, { "a", "b", "c" }, { "d", "e", "f" }, { "g", "h", "i" }, { "j", "k", "l" }, { "m", "o", "n" }, { "p", "q", "r", "s" }, { "t", "u", "v" }, { "w", "x", "y", "z" } }; public List<String> letterCombinations(String digits) { List<String> rList = new ArrayList<>(); int number = 0; if (digits.length() > 1) { number = Integer.valueOf(digits.substring(0, 1)); List<String> subList = letterCombinations(digits.substring(1)); String[] strings = numbers[number]; for (int i = 0; i < strings.length; i++) { String mLetter = strings[i]; for (String str : subList) { rList.add(mLetter + str); } } } else if (digits.length() == 1) { number = Integer.valueOf(digits); String[] words = numbers[number]; for (int i = 0; i < words.length; i++) { rList.add(words[i]); } } return rList; }}
阅读全文
0 0
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- LeetCode | Letter Combinations of a Phone Number
- leetcode Letter Combinations of a Phone Number
- Leetcode: Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- laydate日期插件案例,结束时间小于开始时间不可选择
- PHP 的连接符号 判断
- [Azure][ARM]关于NSG规则配置时的VirtualNetwork和AzureLoadbalancer参数
- EasyDSS流媒体解决方案之音频转码支持
- 一个简单的TabLayout的使用
- LeetCode 17 Letter Combinations of a Phone Number
- MySQL(四)之MySQL数据类型
- MySQL创建Function时报的1418错误代号解决办法
- svn不同分支代码合并
- AtCoder Grand Contest 010D
- Activity四种启动模式
- java 远程调用api辅助类
- 1、python web方向Django入门—基础篇
- linux下怎么创建启动器(eclipse)