[LeetCode 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"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
DiffcultyMedium
Similar Problems
[LeetCode ] Generate Parentheses Medium
[LeetCode ] Combination Sum Medium
[LeetCode ] Binary Watch Easy
Analysis
class Solution {
public:
vector
void findLettComb(string &digits, int index, string dict[], string &comb, vector<string> &lettComb) {
if(index == digits.size()) {
lettComb.push_back(comb);
return;
}
string lett = dict[digits[index] - '0'];
for(int i = 0; i < lett.length(); i++) {
comb[index] = lett[i];
findLettComb(digits, index+1, dict, comb, lettComb);
}
}
};