## Tuesday, November 18, 2014

### [LeetCode] 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.

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23``` ```class Solution { public: vector letterCombinations(string digits) { vector lettComb; string dict[] = {" ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; string comb(digits.size(),'\0'); findLettComb(digits, 0, dict, comb, lettComb); return lettComb; } void findLettComb(string &digits, int index, string dict[], string &comb, vector &lettComb) { if(index==digits.size()) { lettComb.push_back(comb); return; } string lett= dict[digits[index] - '0']; for(int i=0; i

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21``` ```class Solution { public: vector letterCombinations(string digits) { vector lettComb; lettComb.push_back(""); string dict[] = {" ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; for(int i=0; i