Letter Combinations of a Phone Number
来源:互联网 发布:阿里云对象存储价格 编辑:程序博客网 时间:2024/06/07 06:36
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"].
递归,深度优先搜索
public class Solution {public List<String> letterCombinations(String digits) {List<String> res = new ArrayList<String>();String strs[] = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs","tuv", "wxyz" };if (digits == null || digits.length() == 0) {res.add("");return res;}if (digits.length() == 1) {int k = Integer.parseInt(digits);if (k < 2) {res.add("");return res;}String s = strs[k];for (int i = 0; i < s.length(); i++) {res.add(s.charAt(i) + "");}return res;}List<String> temp = letterCombinations(digits.substring(1));String str = strs[Integer.parseInt(digits.substring(0, 1))];if (str == "") {return temp;}for (int i = 0; i < str.length(); i++) {for (int j = 0; j < temp.size(); j++) {res.add(str.charAt(i) + temp.get(j));}}return res;}}
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
- Xcode调试时无法看到变量值
- 断言(ASSERT)的用法
- objective c - 单例模式(多线程)
- nginx tomcat 集群
- Activity intent经常使用的 FLAG 集合
- Letter Combinations of a Phone Number
- hdu 1108最小公倍数
- 安卓TCP通信程序客户端设计
- java使用JNI调用DLL动态库错误
- Activity的四种launchMode
- UI效率
- 数据访问接口功能及含义
- 给定一个数组,按序排列,从数组找出若干个数,使得这若干个数字的和与M最为接近,(背包问题)
- 安卓中使用HTTP从网络下载文件到SD卡程序