Skip to content

Commit

Permalink
Merge pull request #460 from Shubhra-Narang/main
Browse files Browse the repository at this point in the history
Create solution.cpp
  • Loading branch information
bh-g authored Jan 23, 2024
2 parents 163aed9 + 9e8731d commit 7b4b359
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
```
class Solution {
public:
void generate(string &digits, int i,string &t, vector<string>&ans, vector<vector<char>>&m){
if(i==digits.size()){
ans.push_back(t);
return;
}
for(int j=0;j<m[digits[i]-'2'].size();j++){
t+=m[digits[i]-'2'][j];
generate(digits,i+1,t,ans,m);
t.pop_back();
}
}
vector<string> letterCombinations(string digits) {
vector<string>ans;
int n=digits.size();
if(n==0)return ans;
vector<vector<char>>m;
m.push_back({'a','b','c'});
m.push_back({'d','e','f'});
m.push_back({'g','h','i'});
m.push_back({'j','k','l'});
m.push_back({'m','n','o'});
m.push_back({'p','q','r','s'});
m.push_back({'t','u','v'});
m.push_back({'w','x','y','z'});
string t="";
generate(digits,0,t,ans,m);
return ans;
}
};
```

0 comments on commit 7b4b359

Please sign in to comment.