思路:用深搜遍历九宫格字符串,一开始做的时候发生了引用指向空地址的问题,后来发现是vector不能直接=赋值。
class Solution {
public:
int len; string map[]={"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
void search(int pos, string res, vector<string>& a, string digits){
if(pos == len) return;
string s = map[digits[pos] - ''];
for (int i = ;i < s.size(); i++)
{
if(pos == len - )a.push_back(res + s[i]);
else search(pos + , res + s[i], a, digits);
}
} vector<string> letterCombinations(string digits) {
vector<string> ans;
len = digits.size();
if(len == )return ans;
search(,"",ans,digits);
return ans;
}
};