Letter Combinations of a Phone Number
来源:互联网 发布:mac如何使用外置光驱 编辑:程序博客网 时间:2024/06/05 19:37
public class Solution { public List<String> letterCombinations(String digits) { List<String> result = new ArrayList<String>(); if (digits == null || digits.length() == 0) { return result; } Map<Character, char[]> map = new HashMap<Character, char[]>(); map.put('0', new char[] {}); map.put('1', new char[] {}); map.put('2', new char[] { 'a', 'b', 'c' }); map.put('3', new char[] { 'd', 'e', 'f' }); map.put('4', new char[] { 'g', 'h', 'i' }); map.put('5', new char[] { 'j', 'k', 'l' }); map.put('6', new char[] { 'm', 'n', 'o' }); map.put('7', new char[] { 'p', 'q', 'r', 's' }); map.put('8', new char[] { 't', 'u', 'v'}); map.put('9', new char[] { 'w', 'x', 'y', 'z' }); StringBuilder sb = new StringBuilder(); myLetterCombinations(result, sb, digits, map); return result; } private void myLetterCombinations(List<String> result, StringBuilder sb, String digits, Map<Character, char[]> map) { if (sb.length() == digits.length()) { result.add(sb.toString()); return; } for (char ch : map.get(digits.charAt(sb.length()))) { sb.append(ch); myLetterCombinations(result, sb, digits, map); sb.deleteCharAt(sb.length() - 1); } }}
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
- LeetCode18:Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- 按回车自动跳到下一个dialog
- Redis安装问题
- 1、hamr的安装
- 因子和质数
- 甘特图-----PRM -PS 生产排程
- Letter Combinations of a Phone Number
- 使用JDBC连接MySQL数据库--典型案例分析(六)----实现账户转账操作
- Apache Tika
- SpringMVC源码分析系列
- JAVA编程思想-访问权限控制
- EXT.NET 后台获取MultiComboBox的值(多选框)
- jquery自定义控件验证篇
- 机器学习算法原理与实践(四)、AdaBoost算法详解与实战
- Codeforces Looksery Cup 2015