-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path728.java
More file actions
65 lines (59 loc) · 1.83 KB
/
728.java
File metadata and controls
65 lines (59 loc) · 1.83 KB
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
59
60
61
62
63
64
65
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> selfDivNums = new ArrayList<>();
for (int i = left; i <= right; i++) {
if(checkSelfDiv(i)) {
//System.out.println(i);
selfDivNums.add(i);
}
}
return selfDivNums;
}
public boolean checkSelfDiv(int number) {
if (number < 10 && number > 0) return true;
int res = number;
while (res > 0) {
int temp = res % 10;
if (temp == 0) return false;
//System.out.println(temp);
if(!(number % temp == 0)) {
return false;
}
res/= 10;
}
return true;
}
}
__________________________________________________________________________________________________
sample 32348 kb submission
class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
List ans = new ArrayList();
for(int i = left; i <= right; i++)
{
int num = i;
boolean x = false;
while(num > 0){
int temp = num%10;
if(temp == 0)
{
x = false;
break;
}
x = i%temp ==0 ? true : false;
if (!x)
{
x = false;
break;
}
num/=10;
}
if(x)
ans.add(i);
}
return ans;
}
}
__________________________________________________________________________________________________