-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path17.cpp
More file actions
24 lines (24 loc) · 726 Bytes
/
Copy path17.cpp
File metadata and controls
24 lines (24 loc) · 726 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
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string>result;
if(digits.length()==0){
return result;
}
string map[]={"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
solve(digits,map,"",0,result);
return result;
}
void solve(string digits,string map[],string ans,int index,vector<string>&result){
if(index==digits.length()){
result.push_back(ans);
return;
}
else {
string letter=map[digits[index]-'0'];
for(int i=0;i<letter.length();i++){
solve(digits,map,ans+letter[i],index+1,result);
}
}
}
};