leetcode 算法 17. Letter Combinations of a Phone Number
来源:互联网 发布:阿里云怎么搭建vpn免流 编辑:程序博客网 时间:2024/06/05 13:27
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"].
i=0 -> result=combine("abc", [""]) ---> [a,b,c];
i=1 -> result=combine("def", [a,b,c]) ---> [ad,bd,cd, ae,be,ce, af,bf,cf];
``` java
public List<String> letterCombinations(String digits) {
String digitletter[] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
List<String> result =new ArrayList<String>();
if (digits.length()==0) return result;
result.add("");//这一段让下面 List<String> l不为空,直接填填充
for (int i = 0; i < digits.length(); i++) {
result = combine( digitletter[digits.charAt(i)-'0'],result);
}
return result;
}
public static List<String> combine(String digit, List<String> l) {
List<String> result = new ArrayList<String>();
for (int i = 0; i < digit.length(); i++) {
for (String x : l) {
result.add(x+digit.charAt(i));
}
}
return result;
}
```
- leetcode 算法 17. 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
- 数据表的数据的复制 (同一个库 最简单版本)
- 软件内部更新,出现“解析包时出现问题”的错误后停止
- 用ncverilog跑仿真时,如何去除对特定路径的timing检查
- Gin html模板引用
- 20171020.03
- leetcode 算法 17. Letter Combinations of a Phone Number
- js中数组的用法
- 长整数排序(指针专题)
- conv2、filter2、imfilter的区别
- MySQL的并集、差集
- 抓取淘宝评论
- 第三方短信验证
- 剑指Offer(一)二维数组中的查找
- 科学的解决Http Token拦截器实现【详细 一篇足矣】