-
Notifications
You must be signed in to change notification settings - Fork 1
/
letterCOmbinationsPhone.cpp
68 lines (57 loc) · 1.13 KB
/
letterCOmbinationsPhone.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <unordered_map>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
unordered_map<char,string> direc = {
{'2',"abc"},
{'3',"def"},
{'4', "ghi"},
{'5',"jkl"},
{'6',"mno"},
{'7',"pqrs"},
{'8',"tuv"},
{'9',"wxyz"}
};
class Solution {
private:
vector<string> solve(vector<string> &str1,string str2){
vector<string> ans;
for (auto it : str1){
for(auto it2 : str2){
ans.push_back(it+it2);
}
}
return ans;
}
public:
vector<string> letterCombinations(string digits) {
vector<string> ans;
if(digits.length()<1)return ans;
int n = digits.size();
char beg = digits[0];
for(auto it: direc[beg]){
ans.push_back(string(1,it));
}
for (int i=0;i<n;i++){
ans=solve(ans,direc[digits[i]]);
}
return ans;
}
};
int main(){
Solution s;
s.letterCombinations("23234231237129334245");
cout<<"done";
return 0;
}
/*
[2,3]
2
/ | \
[a b c]
| | |
3 3 3
/|\ /|\ /|\
[def] [def] [def]
*/