-
Notifications
You must be signed in to change notification settings - Fork 0
/
017.cpp
46 lines (46 loc) · 988 Bytes
/
017.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public:
// bug 1
char f[10][4]={
{},
{},
{'a','b','c'},
{'d','e','f'},
{'g','h','i'},
{'j','k','l'},
{'m','n','o'},
{'p','q','r','s'},
{'t','u','v'},
{'w','x','y','z'}
};
vector<string> ans;
vector<string> letterCombinations(string digits) {
int n = digits.size();
fun(0,digits,"",n);
// bug 2
if(digits=="") return (vector<string>){};
return ans;
}
void fun(int i,string d,string s,int n){
if(i==n) ans.push_back(s);
int j=0;
while(i<n && j<4){
int num = d[i]-'0';
//bug 0
if(!f[num][j]) break;
s.push_back(f[num][j]);
fun(i+1,d,s,n);
s.pop_back();
j++;
}
return;
}
};
/*
- No zuo no die why you try;
- In fact, if I use string [] dict ={"abc","def",...} is better.
- If so, the length of letters is countable, no need to special judge the j-th digit is ''
- The bug of the special input "" is gross. I don't know if it happens using dict;
- substr(indexOfBegin, length)
- substr(index)
*/