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"].
1 vector<string> letterCombinations(string digits) { 2 string trans[] = {"", " ", "abc", "def", "ghi", "jkl", 3 "mno", "pqrs", "tuv", "wxyz"}; 4 vector<string> set; 5 string seq; 6 Generater(trans, digits, 0, seq, set); 7 return set; 8 } 9 void Generater(string trans[], string& digits, 10 int deep, string& result, vector<string>& set) 11 { 12 if(deep == digits.size()) 13 { 14 set.push_back(result); 15 return; 16 } 17 int curDig = digits[deep] - 48; 18 for(int i =0; i < trans[curDig].size(); i++) 19 { 20 result.push_back(trans[curDig][i]); 21 Generater(trans, digits, deep+1, result, set); 22 result.resize(result.size() -1); 23 } 24 }