Ad
Algorithms
Code
Diff
  • fn digits(n: u64) -> usize {
        n.to_string().len()
    }
    • fn digits(mut n: u64) -> usize {
    • std::iter::from_fn(|| { n = n / 10; Some(n) }).
    • take_while(|n| *n > 0)
    • .count() + 1
    • fn digits(n: u64) -> usize {
    • n.to_string().len()
    • }
Code
Diff
  • fn flip_the_number(x: &u64) -> u64 {
        x.to_string().chars().rev().collect::<String>().parse().unwrap()
    }
    • fn flip_the_number(x: &u64) -> u64 {
    • let mut x = *x;
    • let mut y = 0;
    • while x != 0 {
    • y = y * 10 + x % 10;
    • x /= 10;
    • }
    • y
    • x.to_string().chars().rev().collect::<String>().parse().unwrap()
    • }
Code
Diff
  • fn solution(x: i32) -> bool {
        x.to_string().contains('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().contains('3')
    • }