classSolution: defselfDividingNumbers(self, left: int, right: int) -> List[int]: defisSelfDividing(num: int) -> bool: x = num while x: x, d = divmod(x, 10) if d == 0or num % d: returnFalse returnTrue return [i for i inrange(left, right + 1) if isSelfDividing(i)]
classSolution { public List<Integer> selfDividingNumbers(int left, int right) { List<Integer> ans = newArrayList<Integer>(); for (inti= left; i <= right; i++) { if (isSelfDividing(i)) { ans.add(i); } } return ans; }
publicclassSolution { public IList<int> SelfDividingNumbers(int left, int right) { IList<int> ans = new List<int>(); for (int i = left; i <= right; i++) { if (IsSelfDividing(i)) { ans.Add(i); } } return ans; }
publicboolIsSelfDividing(int num) { int temp = num; while (temp > 0) { int digit = temp % 10; if (digit == 0 || num % digit != 0) { returnfalse; } temp /= 10; } returntrue; } }
var selfDividingNumbers = function(left, right) { const ans = []; for (let i = left; i <= right; i++) { if (isSelfDividing(i)) { ans.push(i); } } return ans; }