-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathLetter_Combination.cpp
More file actions
35 lines (30 loc) · 766 Bytes
/
Letter_Combination.cpp
File metadata and controls
35 lines (30 loc) · 766 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
#include <iostream>
#include <vector>
using namespace std;
void solve(string digits, int i, int n, string comb, vector<string> &ans)
{
if (i == n)
{
ans.push_back(comb);
return;
}
solve(digits, i + 1, n, comb + char(((digits[i] - '0') - 2) * 3), ans);
solve(digits, i + 1, n, comb + char(((digits[i] - '0') - 2) * 3 + 1), ans);
solve(digits, i + 1, n, comb + char(((digits[i] - '0') - 2) * 3 + 2), ans);
}
vector<string> letterCombinations(string digits)
{
vector<string> ans;
int n = digits.length();
if (n == 0)
return ans;
solve(digits, 0, n, "", ans);
return ans;
}
int main()
{
vector<string> ans = letterCombinations("23");
for(auto i: ans)
cout<<i<<endl;
return 0;
}