时间复杂度O(n^3),n是s的长度;
空间复杂度O(n^3)
vector<string> solution(string s)
{
char r[8][4] = { { 'A', 'B', 'C', ' ' }, { 'D', 'E', 'F', ' ' }, { 'G', 'H', 'I', ' ' }, { 'J', 'K', 'L', ' ' }, { 'M', 'N', 'O', ' ' }, { 'P', 'O', 'R', 'S' }, { 'T', 'U', 'V', ' ' }, { 'W', 'X', 'Y', 'Z' } };
vector <string> sv;
if (s[0] < '0' || s[0] > '9')
return sv;
int it = s[0] - '0';
it -= 2;
for (int i = 0; i < (it == 5 || it == 7 ? 4 : 3); ++i)
{
string st = "";
if (it >= 0)
st = st + r[it][i];
sv.push_back(st);
}
for (int i = 1; i < s.length(); ++i)
{
int length = sv.size();
for (int j = 0; j < length; ++j)
{
if (s[i] < '0' || s[i] > '9')
{
vector <string> sv;
return sv;
}
int it = s[i] - '0';
it -= 2;
if (it >= 0)
{
string st = sv[j];
sv.push_back(st + r[it][1]);
sv.push_back(st + r[it][2]);
if (it == 5 || it == 7)
sv.push_back(st + r[it][3]);
sv[j] += r[it][0];
}
}
}
return sv;
}