Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.
Example:
Input: “23”
Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].
这个题可能是在考 for 循环吧…
class Solution {
public:
vector<string> letterCombinations(string digits) {
if(digits == "") return vector<string>();
vector<string> res;
string m[10] = {"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
res.push_back("");
int len=digits.length();
for(int i=0;i<len;i++){
vector<string> tmp;
for(int j=0;j<m[digits[i]-'0'].length();j++)
for(int k=0;k<res.size();k++)
tmp.push_back(res[k]+m[digits[i]-'0'][j]);
res=tmp;
}
return res;
}
};