Problem Description
Given an integer num, count the number of digits in num that evenly divide num (i.e., for a digit d, num % d == 0). Each occurrence of a digit that divides num is counted, and the number does not contain any zero digits.
Key Insights
- Convert the number to a string to iterate over each digit.
- For each digit, convert it back to an integer and check if it divides the number evenly using the modulo operation.
- Since the number does not contain zero, directly perform the division check.
- Each valid digit, even if repeated, is counted separately.
Space and Time Complexity
Time Complexity: O(d), where d is the number of digits in num (log10(num)).
Space Complexity: O(d) for storing the string representation, which is negligible.
Solution
The solution involves converting the integer to its string representation to easily iterate over each digit. For each digit, convert it back into an integer and check if it divides the original integer without leaving a remainder using the modulo operator. A counter is incremented each time a digit divides the number evenly. This simple linear approach handles all cases and respects the constraints of the problem.