2520. Count the Digits That Divide a Number ¶ Time: $O(\log\texttt{num})$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: int countDigits(int num) { int ans = 0; for (int n = num; n > 0; n /= 10) if (num % (n % 10) == 0) ++ans; return ans; } }; 1 2 3 4 5 6 7 8 9 10 11class Solution { public int countDigits(int num) { int ans = 0; for (int n = num; n > 0; n /= 10) if (num % (n % 10) == 0) ++ans; return ans; } } 1 2 3class Solution: def countDigits(self, num: int) -> int: return sum(num % int(d) == 0 for d in str(num))