【DFS】Letter Combinations of a Phone Number
来源:互联网 发布:手机永不休眠软件 编辑:程序博客网 时间:2024/06/01 22:09
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.
public class Solution { public String[] ss = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; public ArrayList<String> res = new ArrayList<String>(); public void dfs(String digits, String str, int pos){ if(str.length() == digits.length()){ res.add(str); return ; } int t = Integer.parseInt("" + digits.charAt(pos)); String st = ss[t]; for(int j=0; j<st.length(); j++){ dfs(digits, str+st.charAt(j), pos+1); } } public ArrayList<String> letterCombinations(String digits) { dfs(digits, "", 0); return res; }}
0 0
- 【DFS】Letter Combinations of a Phone Number
- DFS Letter Combinations of a Phone Number
- Leetcode dfs Letter Combinations of a Phone Number
- Leetcode Letter Combinations of a Phone Number DFS
- LeetCode Letter Combinations of a Phone Number DFS
- LeetCode OJ-17.Letter Combinations of a Phone Number(DFS)
- Letter Combinations of a Phone Number(回溯,dfs)
- 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
- Java 内存分配全面浅析
- 用SQL写的18位身份证校验代码
- 大数据量高并发的数据库优化
- 算法第二周作业:名词解释
- chown命令的用法
- 【DFS】Letter Combinations of a Phone Number
- cookie
- 旋转正四面体
- C语言语句及流程控制
- 海量sql语句查询代码优化
- http服务器端工作流程
- 利用SqlHelper.cs实现Web程序与数据库的连接
- [Git]03 如何查看提交历史
- C# 读取excel 文件的方法