#2520
Easy Algorithms Count the digits that divide a number
Math
85.9% acceptance
Feb 25, 2026
672
42
Given an integer num, return the number of digits in num that divide num.
An integer val divides nums if nums % val == 0.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn count_digits(num: i32) -> i32 {
let mut n = num;
let mut count = 0;
while n > 0 {
let d = n % 10;
if num % d == 0 {
count += 1;
}
n /= 10;
}
count
}
}