# leetcode 017 —— 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"].

class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> table={"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
vector<string> res;
if (digits.empty()) return res;
scan(0, "", digits, table, res);
return res;

}
void scan(int level, string path, string &digits, vector<string> &table,vector<string> &res){
if (level == digits.size()){
res.push_back(path);
return;
}
for (int i = 0; i < table[digits[level] - '0'].size(); i++){
path.push_back(table[digits[level] - '0'][i]);
scan(level + 1, path, digits, table, res);
path.pop_back();
}
}
};

06-14 1159

05-10 2803

04-07 1887

08-17 1273

05-29 693

04-29 4911

03-04 2938

01-30 3210

07-06 3230

07-02 689