forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCount_good_numbers
More file actions
31 lines (31 loc) · 744 Bytes
/
Count_good_numbers
File metadata and controls
31 lines (31 loc) · 744 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
25
26
27
28
29
30
31
void help(vector<int>& res,int l,int r,int d){
if(l>r)return;
vector<int> dig;
int x=l,f=0;
while(x>0){
if(x%10==d){
f=1;
break;
}
dig.push_back(x%10);
x/=10;
}
if(!f){
int a=0;
for(int i=1;i<dig.size();i++){
if(dig[i]<=dig[i-1]){
a=1;
break;
}
dig[i]+=dig[i-1];
}
if(!a)res.push_back(l);
}
help(res,l+1,r,d);
}
vector<int> goodNumbers(int L, int R, int D) {
// code here
vector<int> res;
help(res,L,R,D);
return res;
}