Solution :
1 class Solution {
2 public:
3 vector<string> letterCombinations(string digits) {
4 if(digits.empty()) return vector<string>();
5 vector<string> list={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
6 vector<string> res;
7 res.push_back("");
8 for(int i=0;i<digits.size();i++){
9 if(digits[i]>'9'||digits[i]<'0') continue;
10 int num=digits[i]-'0';
11 vector<string> tmp;
12 for(int k=0;k<list[num].size();k++){
13 for(int j=0;j<res.size();++j){
14 tmp.push_back(res[j]+list[num][k]);
15 }
16 }
17 res.swap(tmp);
18 }
19 return res;
20 }
21 };