-
Notifications
You must be signed in to change notification settings - Fork 0
/
728. Self Dividing Numbers
57 lines (52 loc) · 1.48 KB
/
728. Self Dividing Numbers
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
class Solution {
public:
vector<int> selfDividingNumbers(int left, int right) {
int i = 0, j = 0, k= 0;
bool flag = 1;
vector<int> ans;
for(i = left; i <= right; i++){
flag = 1;
if(i < 10){
ans.push_back(i);
}else if(i < 100){
j = i % 10;
// cout << "i = " << i << ";" << "j =" << j << endl;
if(j == 0){
continue;
}
if(i % j == 0){
j = i / 10;
if(i % j == 0){
ans.push_back(i);
}
}
}else{
k = i % 10;
if(k == 0){
continue;
}
j = i;
while(k > 0){
if(i % k != 0){
flag = 0;
break;
}
j = j / 10;
if(j < 10){
k = j;
}else{
k = j % 10;
}
if(k == 0 && j > 0){
flag = 0;
break;
}
}
if(flag){
ans.push_back(i);
}
}
}
return ans;
}
};