classSolution{ public List<Integer> selfDividingNumbers(int left, int right){ List<Integer> ans = new ArrayList(); for (int n = left; n <= right; ++n) { if (selfDividing(n)) ans.add(n); } return ans; } publicbooleanselfDividing(int n){ for (char c: String.valueOf(n).toCharArray()) { if (c == '0' || (n % (c - '0') > 0)) returnfalse; } returntrue; } /* Alternate implementation of selfDividing: public boolean selfDividing(int n) { int x = n; while (x > 0) { int d = x % 10; x /= 10; if (d == 0 || (n % d) > 0) return false; } return true; */ }