forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_728.java
30 lines (27 loc) · 812 Bytes
/
_728.java
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
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.List;
public class _728 {
public static class Solution1 {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> result = new ArrayList<>();
for (int num = left; num <= right; num++) {
if (isSelfDividing(num)) {
result.add(num);
}
}
return result;
}
private boolean isSelfDividing(int num) {
int tmp = num;
while (tmp != 0) {
int digit = tmp % 10;
if (digit == 0 || num % digit != 0) {
return false;
}
tmp /= 10;
}
return true;
}
}
}