-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
35 lines (34 loc) · 922 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public:
map<char, vector<char>> d2s;
vector<string> letterCombinations(string digits) {
char c, i;
for(c = 'a', i = '2'; c < 'y'; i++)
{
d2s[i].push_back(c++);
d2s[i].push_back(c++);
d2s[i].push_back(c++);
if(i == '7')
d2s[i].push_back(c++);
}
d2s['9'].push_back('z');
vector<string> res;
if(digits.size() == 0)
return res;
mapDS(res, digits, "");
return res;
}
void mapDS(vector<string>& res, string digits, string str){
int l = digits.size();
if(l == 0)
{
res.push_back(str);
return;
}
vector<char> temp = d2s[digits[0]];
for(auto i = temp.begin();i != temp.end(); i++)
{
mapDS(res, digits.substr(1, l-1), str + (*i));
}
}
};