leetcode 728. Self Dividing Numbers

class Solution {
public List selfDividingNumbers(int left, int right) {
List ans = new ArrayList<>();
for(int i = left; i <= right; i++) {
if(isIn(i)) {
ans.add(i);
}
}
return ans;
}
private boolean isIn(int num) {
char[] theInt = String.valueOf(num).toCharArray();
//先转成字符串,再变成字符数组
for(int i = 0; i < theInt.length; i++) {
int temp = theInt[i] - '0';
if(temp == 0) return false; //题目中说了数字中不允许出现‘0’,这里是个坑
if(num % temp != 0) return false;
}
return true;
}
}

原文地址:https://www.cnblogs.com/huangming-zzz/p/10660162.html