# Middle-题目72：17. Letter Combinations of a Phone Number

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”].

public class Solution {
private String[][] letters = new String[][] {
{" "},
{},
{"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) {
List<String> list = new ArrayList<String>();
if(digits.length() > 0)
backtrack(list, digits, new String(), 0);
return list;
}
private void backtrack(List<String> list, String digits, String currentLetter, int index) {
if(index == digits.length()) {
return;
}
else {
int num = digits.charAt(index) -'0';
for(int i = 0; i < letters[num].length; i++) {
currentLetter+=letters[num][i];
backtrack(list, digits, currentLetter, index+1);
currentLetter = currentLetter.substring(0,currentLetter.length()-1);
}
}
}
}

1ms，beats 46.02%，众数1ms,53.98%

• 本文已收录于以下专栏：

## LeetCode 17 Letter Combinations of a Phone Number(C,C++,Java,Python)

Problem: Given a digit string, return all possible letter combinations that the number could re...
• runningtortoises
• 2015年05月10日 13:39
• 2316

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

[Java]LeetCode17 Letter Combinations of a Phone Number
• fumier
• 2015年04月24日 09:47
• 959

## 17. Letter Combinations of a Phone Number-python

Leetcode上对deque不支持，所以用list和游标模拟队列，应为这个题目是队列的经典应用。原题Given a digit string, return all possible letter ...
• daigualu
• 2017年07月02日 10:03
• 577

## [leetcode] 17. Letter Combinations of a Phone Number ,python实现【medium】

Letter Combinations of a Phone Number Given a digit string, return all possible letter comb...
• zl87758539
• 2016年06月14日 22:25
• 786

## LeetCode --- 17. Letter Combinations of a Phone Number

• makuiyu
• 2015年01月30日 21:30
• 2541

## 【LeetCode】LeetCode——第17题：Letter Combinations of a Phone Number

【LeetCode】LeetCode——第17题：Letter Combinations of a Phone Number
• hujingshuang
• 2016年04月29日 21:40
• 4668

## [leetcode-17]Letter Combinations of a Phone Number(java)

• zdavb
• 2015年07月27日 14:29
• 427

## 【LeetCode】C# 17、Letter Combinations of a Phone Number

• qq_39643935
• 2017年10月09日 12:12
• 61

## LeetCode #17 Letter Combinations of a Phone Number C# Solution

Given a digit string, return all possible letter combinations that the number could represent. e...
• daypig
• 2016年06月01日 21:19
• 365

## LeetCodet题解--17. Letter Combinations of a Phone Number（所有数字键盘组合所对应的所有字符集合）

• gatieme
• 2016年04月07日 16:53
• 1586

举报原因： 您举报文章：Middle-题目72：17. Letter Combinations of a Phone Number 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)