-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.cpp
More file actions
24 lines (24 loc) · 684 Bytes
/
Copy path17.cpp
File metadata and controls
24 lines (24 loc) · 684 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:
string maps[10]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
vector<string> res;
void trace(string &s,string &digits,int index){
if(index==digits.length()){
res.push_back(string(s));
return;
}
string letters=maps[digits[index]-'0'];
int len=letters.length();
for(int i=0;i<len;i++){
s+=letters[i];
trace(s,digits,index+1);
s.pop_back();
}
}
vector<string> letterCombinations(string digits) {
if(digits.length()==0){return res;}
string tmp="";
trace(tmp,digits,0);
return res;
}
};