-
Notifications
You must be signed in to change notification settings - Fork 12
/
AshleyLovesNumbers.cpp
58 lines (47 loc) · 1.15 KB
/
AshleyLovesNumbers.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
47
48
49
50
51
52
53
54
55
56
57
58
// 7/11 test cases passed
void check(int a, int b, string s, int& ans, map<int, bool> m){
int n = stoi(s), len = s.size();
if((n >= a) && (n <= b)){
ans++;
}
else if(n > b){
return;
}
for(int i = 0; i <= 9; i++){
if(m.find(i) == m.end()){
m[i] = true;
check(a, b, s + to_string(i), ans, m);
}
}
}
bool check(string s){
map<int, bool> m;
for(int i = 0; i < s.size(); i++){
if(m.find(s[i] - '0') == m.end()){
m[s[i] - '0'] = true;
}
else{
return false;
}
}
return true;
}
void countNumbers(vector < vector < int > > arr) {
int rows = arr.size();
for(int i = 0; i < rows; i++){
int a = arr[i][0], b = arr[i][1], ans = 0;
/*
for(int i = 1; i <= 9; i++){
map<int, bool> m;
m[i] = true;
check(a, b, to_string(i), ans, m);
}
*/
for(int i = a; i <= b; i++){
if(check(to_string(i))){
ans++;
}
}
cout << ans << endl;
}
}