17,Letter Combinations of a Phone Number
来源:互联网 发布:实时天气预报软件电脑 编辑:程序博客网 时间:2024/06/03 15:17
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.
题目分析:
解法很简单,就是递归,直接上代码。
代码如下:
public class Solution {private String[] numToChar={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};public void getAll(String digits,int pos,StringBuilder builder,List<String> list){//判断是否应该输出if(pos>=digits.length()){list.add(builder.toString());return;}//获得当前数字int num=digits.charAt(pos)-'0';for(int i=0;i<numToChar[num].length();++i){//添加builder.append(numToChar[num].charAt(i));getAll(digits, pos+1, builder, list);//删除builder.deleteCharAt(builder.length()-1);}return;} public List<String> letterCombinations(String digits) { List<String> list=new LinkedList<String>(); if(digits==null||digits.length()<1) return list; StringBuilder builder=new StringBuilder(); getAll(digits, 0, builder, list); return list; }}
0 0
- 17,Letter Combinations of a Phone Number
- #17 Letter Combinations of a Phone Number
- 17Letter Combinations of a Phone Number
- 17 Letter Combinations of a Phone Number
- 17 Letter Combinations of a Phone Number
- 【17】Letter Combinations of a Phone Number
- 17 Letter Combinations of a Phone Number
- 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
- 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
- Postgresql 恢复一例
- Spring properties定义bean
- 【转】本地复制不能粘贴到服务器上
- 《线上推广方法》
- 队列操作(一)
- 17,Letter Combinations of a Phone Number
- 网络学习笔记:子网掩码
- 如何整合S2SH(三)
- Boss OpenCart 商城自适应主题模板 ABC-0012-01
- URAL1826 Minefield(简单递归)
- 我的3D游戏消息泵1
- 【OpenCL】初学摘要(一)
- Plan Procurement Outputs You Should Know for the PMP Certification Exam
- 二级 求26个英语字母在字符串中的出现次数