Ad
Algorithms
Code
Diff
  • fn digits(mut n: u64) -> usize {
        std::iter::from_fn(|| { n = n / 10; Some(n) }).
            take_while(|n| *n > 0)
            .count() + 1
    }
    • use std::collections::BTreeMap;
    • fn digits(n: u64) -> usize {
    • let powers = (0..20).map(|n| (
    • if n == 0 { 0 } else { 10_u64.pow(n) },
    • n as usize + 1
    • )).collect::<BTreeMap<_, _>>();
    • return *powers.range(..=n).last().unwrap().1;
    • fn digits(mut n: u64) -> usize {
    • std::iter::from_fn(|| { n = n / 10; Some(n) }).
    • take_while(|n| *n > 0)
    • .count() + 1
    • }
Code
Diff
  • fn solution(x: i32) -> bool {
        x.to_string().chars().any(|s| s == '3')
    }
    • fn solution(mut x: i32) -> bool {
    • match x.to_string().chars().into_iter().position(|s| s == '3') {
    • Some(_t) => true,
    • _e => false,
    • }
    • fn solution(x: i32) -> bool {
    • x.to_string().chars().any(|s| s == '3')
    • }