Skip to content

Commit e66dd79

Browse files
authored
Merge pull request larissalages#56 from tanya-0708/new-user
Added solution to Letter Combinations of a Phone Number in a leetcode…
2 parents c4a8a95 + bca66ca commit e66dd79

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
4+
5+
6+
vector<string> letterCombinations(string digits) {
7+
vector <string> t{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
8+
vector<string> ans;
9+
if(digits.length()==0)
10+
return {};
11+
findans(t,ans,digits,"");
12+
return ans;
13+
14+
}
15+
void findans(vector<string>& t,vector<string>& ans,string s,string path)
16+
{
17+
if(s.length()==0)
18+
{ ans.push_back(path);
19+
return;
20+
}
21+
22+
string temp=t[s[0]-'2'];
23+
for(int i=0;i<temp.length();i++)
24+
{
25+
findans(t,ans,s.substr(1,s.length()-1),path+temp[i]);
26+
}
27+
}
28+
};

0 commit comments

Comments
 (0)