-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone.cpp
More file actions
47 lines (35 loc) · 920 Bytes
/
Copy pathphone.cpp
File metadata and controls
47 lines (35 loc) · 920 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
38
39
40
41
42
43
44
45
46
47
// https://leetcode.com/explore/interview/card/facebook/53/recursion-3/267/
#include <bits/stdc++.h>
using namespace std;
unordered_map<char, vector<char>> Ph = {
{'1',{}},
{'2', {'a','b','c'}},
{'3', {'d','e','f'}}
};
class Solution {
void lc(string& digits, long unsigned int i, string sofar, vector<string> & r) {
if (i == digits.size()){
r.push_back(sofar);
return;
}
char d = digits[i];
for (char c : Ph[d]){
string s = sofar + c;
lc(digits,i+1,s,r);
}
}
public:
vector<string> letterCombinations(string digits) {
vector<string> r;
lc(digits,0,"",r);
return r;
}
};
// To execute C++, please define "int main()"
int main() {
Solution sol;
for (auto s: sol.letterCombinations("23")){
cout << s << ",";
}
return 0;
}