-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17_letterCombinations.cpp
More file actions
37 lines (37 loc) · 955 Bytes
/
17_letterCombinations.cpp
File metadata and controls
37 lines (37 loc) · 955 Bytes
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
36
37
class Solution {
public:
map<int,string> alph;
vector<string> res;
void Add(string tmp,int ind,string d){
if(ind == d.size()-1){
string a = alph.find(d[ind]-'0')->second;
for(int i = 0;i<a.size();i++){
string b = tmp;
tmp+=a[i];
res.push_back(tmp);
tmp = b;
}
return;
}
string a = alph.find(d[ind]-'0')->second;
for(int i = 0;i<a.size();i++){
string b = tmp;
tmp+=a[i];
Add(tmp,ind+1,d);
tmp = b;
}
}
vector<string> letterCombinations(string digits) {
alph[2] = "abc";
alph[3] = "def";
alph[4] = "ghi";
alph[5] = "jkl";
alph[6] = "mno";
alph[7] = "pqrs";
alph[8] = "tuv";
alph[9] = "wxyz";
string tmp = "";
Add(tmp,0,digits);
return res;
}
};