LeetCode17
来源:互联网 发布:什么是ba无标度网络 编辑:程序博客网 时间:2024/05/15 21:05
【题目】
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.
【思路】
直接采用递归
【Java代码】
public class Solution_17_letter_combinations_of_a_phone_number {String[][] dict = {{"a","b","c"},{"d","e","f"},{"g","h","i"},{"j","k","l"},{"m","n","o"},{"p","q","r","s"},{"t","u","v"},{"w","x","y","z"}};public List<String> letterCombinations(String digits){if(digits.length() == 0)return new ArrayList<String>();int index = Character.getNumericValue(digits.charAt(0))-2;if(digits.length() == 1){return Arrays.asList(dict[index]);}else{List<String> curr = letterCombinations(digits.substring(1));List<String>result = new ArrayList<String>();for(int i = 0 ; i < dict[index].length ; i++)for(int j = 0 ; j < curr.size() ; j++)result.add(dict[index][i]+curr.get(j));return result;}}}
阅读全文
0 0
- leetcode17
- LEETCODE17
- LeetCode17
- leetcode17.PalindromePartitioning
- LeetCode17: 4Sum
- Leetcode17: Valid Palindrome
- [LeetCode17]Letter Combinations of a Phone Number
- LeetCode17:Letter Combinations of a Phone Number
- leetcode17 Letter Combinations of a Phone Number
- LeetCode17:Letter Combinations of a Phone Number
- leetcode17---Letter Combinations of a Phone Number
- LeetCode17. Letter Combinations of a Phone Number
- leetcode17:Letter Combinations of a Phone Number
- LeetCode17. Letter Combinations of a Phone Number
- leetcode17. Letter Combinations of a Phone Number
- leetcode17 Letter Combinations of a Phone Number
- [Java]LeetCode17 Letter Combinations of a Phone Number
- leetcode17-根据数字找到可能的按键字母组合
- 使用jquery触发a标签跳转
- MFC上CSerialPort类解决线程内异步…
- 八数码
- VC++ 回调函数+线程回调
- opencv 检测抛出异常 +&…
- LeetCode17
- Navicat使用说明
- 面向对象的三个基本特征(继承)(extends和implements)
- 67. Add Binary(C语言版本)
- iOS极光推送,测试环境可以收到信息,而正式环境收不到的问题
- Android手机屏幕尺寸计算
- java不重复的随机数
- hdu 2056
- android webview 播放视频 全屏问题