Description
A self-dividing number is a number that is divisible by every digit it contains. A self-dividing number cannot contain the digit zero. Given integers left and right, return a list of all self-dividing numbers in the range [left, right].
Examples
left = 1, right = 22[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]All self-dividing numbers in range.
left = 47, right = 53[48]Checking each number: 47 contains 7 but 47/7 is not an integer, 48/4=12 and 48/8=6 (both divisible), 49/9 is not an integer, 50 contains 0 (division undefined), 51/5 is not an integer, 52/5 is not an integer, 53/5 is not an integer. Only 48 is self-dividing.
left = 100, right = 102[]All numbers in this range contain the digit 0, which makes them not self-dividing since division by zero is undefined. 100, 101, and 102 all contain 0, so none can be self-dividing numbers. This demonstrates that any number containing 0 cannot be self-dividing.
Constraints
- •
1 ≤ left ≤ right ≤ 10⁴