4 ms·
No loops, and at least for a 64-bit type, you won't run out of stack space. fn digit_length_recursive(input: usize) -> usize { if input == 0 {
by arcticbull 7y ago
No loops, and at least for a 64-bit type, you won't run out of stack space.
fn digit_length_recursive(input: usize) -> usize {
if input == 0 {
0
} else {
1 + digit_length_recursive(input / 10)
}
}
fn digit_length(input: usize) -> usize {
std::cmp::max(digit_length_recursive(input), 1)
}