Skip to content

Commit ad82b97

Browse files
committed
Adding cpp implementation for 17
1 parent a774c5f commit ad82b97

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution
5+
{
6+
public:
7+
vector<string> m = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
8+
vector<string> ans;
9+
vector<string> letterCombinations(string digits)
10+
{
11+
solve(0, "", digits);
12+
return ans;
13+
}
14+
void solve(int i, string path, string digits)
15+
{
16+
if (i >= digits.size())
17+
{
18+
if (path.size() > 0)
19+
ans.push_back(path);
20+
return;
21+
}
22+
for (auto c : m[digits[i] - '0'])
23+
{
24+
path += c;
25+
solve(i + 1, path, digits);
26+
path.pop_back();
27+
}
28+
}
29+
};
30+
31+
int main()
32+
{
33+
cout << "Enter A string : ";
34+
string s;
35+
cin >> s;
36+
Solution sol;
37+
// vector<string> ans = sol.letterCombinations(s) ;
38+
for (auto str : sol.letterCombinations(s))
39+
{
40+
cout << str << " ";
41+
}
42+
return 0;
43+
}

0 commit comments

Comments
 (0)