-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathGood Number
More file actions
43 lines (26 loc) · 802 Bytes
/
Good Number
File metadata and controls
43 lines (26 loc) · 802 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
32
33
34
35
36
37
38
39
40
41
42
43
bool isvalidNumber(int n, int d){
int digit = n%10;
int sum = digit;
if (digit == d)
return false;
n /= 10;
while (n){
digit = n%10;
if (digit == d || digit <= sum)
return false;
else{
sum += digit;
n /= 10;
}
}
return 1;
}
vector<int> goodNumbers(int L, int R, int digit) {
vector<int> vec;
for (int i=L; i<=R; i++){
if (isvalidNumber(i, digit) == true){
vec.push_back(i);
}
}
return vec;
}