# [LeetCode][Java] Letter Combinations of a Phone Number

593人阅读 评论(0)

## 题目：

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.

## 题意：

Input:Digit string "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].

## 算法分析：

* 思路:

*比如“234”这个字符串，我可以先将0...1的所有排列找到-->{"a", "b", "c"}

*再进一步将0...2的所有排列找到-->{"ad", "ae","af", "bd", "be", "bf", "cd", "ce", "cf"}

*如此循环...直到字符串末尾。实现如下

## AC代码：

public class Solution
{
public  ArrayList<String> letterCombinations(String digits)
{
ArrayList<String> res=new ArrayList<String>();
String charmap[] = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
if (digits.length()==0) return res;
for (int i = 0; i < digits.length(); i++)
{
ArrayList<String> tempres=new ArrayList<String>();
String chars = charmap[digits.charAt(i) - '0'];
for (int c = 0; c < chars.length();c++)
{
for (int j = 0; j < res.size();j++)
}
res = tempres;
}
return res;
}
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：232032次
• 积分：4594
• 等级：
• 排名：第6366名
• 原创：230篇
• 转载：99篇
• 译文：0篇
• 评论：13条
文章分类
最新评论