Skip to content

Commit bbce8fb

Browse files
Merge pull request #5 from akshaysoni10/LeetCode-Solution
Akshay's Leetcode solution is added
2 parents e234812 + 26a4dd5 commit bbce8fb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
private:
3+
void solve(string digit, string output, int index, vector<string>& ans, string mapping[]){
4+
//base case
5+
if(index >= digit.length()){
6+
ans.push_back(output);
7+
return;
8+
}
9+
10+
int number = digit[index] - '0';
11+
string value = mapping[number];
12+
13+
for(int i=0; i<value.length(); i++){
14+
output.push_back(value[i]);
15+
solve(digit, output, index+1, ans, mapping);
16+
output.pop_back();
17+
}
18+
}
19+
20+
public:
21+
vector<string> letterCombinations(string digits) {
22+
vector<string> ans;
23+
if(digits.length()==0){
24+
return ans;
25+
}
26+
string output = "";
27+
int index = 0;
28+
string mapping[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
29+
solve(digits, output, index, ans, mapping);
30+
return ans;
31+
}
32+
};

0 commit comments

Comments
 (0)