17. Letter Combinations of a Phone Number
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> res;
if(digits.empty())
return res;
string map[10]={"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
res.push_back(""); //非空!!
for(int i=0;i<digits.size();i++){
vector<string> temp;
string chars=map[digits[i]-'0'];
for(int j=0;j<res.size();j++){
for(int k=0;k<chars.size();k++){
temp.push_back(res[j]+chars[k]);
}
}
res=temp;
}
return res;
}
};