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"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
没意思。。。。vector update自己的时候每次是原来次数乘以新数字的可能字母的size....所以要用一个tmp在loop的时候装result...
class Solution {
public:
vector<string> letterCombinations(string digits) {
static string querry[]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
vector<string> result={""};
for (int i=0; i<digits.size();i++){
char c=digits[i];
vector<string> tmp;
string local=querry[c-'2'];
for (int j=0; j<local.size(); j++) {
for (int k=0; k<result.size();k++){
string a=result[k]+local[j];
tmp.push_back(a);
}
}
result=tmp;
}
return result;
}
};