-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSelfDividingNumbers_728.java
More file actions
42 lines (38 loc) · 950 Bytes
/
SelfDividingNumbers_728.java
File metadata and controls
42 lines (38 loc) · 950 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
package 数学;
import java.util.ArrayList;
import java.util.List;
/**
* @Author jiangyunxiong
* @Date 2018/12/22 下午1:31
*
* 自除数 是指可以被它包含的每一位数除尽的数。
*/
public class SelfDividingNumbers_728 {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> list = new ArrayList<>();
for (int i = left; i <= right; i++) {
if (i < 10) {
list.add(i);
continue;
}
if (vaild(i)){
list.add(i);
}
}
return list;
}
private boolean vaild(int n) {
int cache = n;
while (n > 1) {
int remain = n%10;
if (remain == 0){
return false;
}
if (cache % remain != 0){
return false;
}
n = (n -remain) /10;
}
return true;
}
}