-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path017.cpp
35 lines (31 loc) · 844 Bytes
/
017.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
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
map<int, string> buttons {
{'1', "*"},
{'2', "abc"},
{'3', "def"},
{'4', "ghi"},
{'5', "jkl"},
{'6', "mno"},
{'7', "pqrs"},
{'8', "tuv"},
{'9', "wxyz"}
};
vector<string> letterCombinations(string digits) {
vector<string> combinations;
for (auto l = buttons[digits[0]].begin(); l != buttons[digits[0]].end(); l++) {
vector<string> next = letterCombinations(digits.substr(1));
if (next.size() == 0)
next.push_back("");
for (auto m = next.begin(); m != next.end(); m++) {
combinations.push_back(*l + *m);
}
}
return combinations;
}
};
int main() {
return 0;
}