Count the digits that divide a number

January 1, 2023

math-and-geometry

Problem URL: Count the digits that divide a number

We will iterate over each digit and check if it is a divisor of the number. If it is, we will increment the counter.

class Solution:
    def countDigits(self, num: int) -> int:
        return sum(num % int(n) == 0 for n in str(num))

Time complexity: O(n)
Space complexity: O(1)