How to check if a string contains identical digits in Rust

1 Answer

0 votes
use std::collections::HashSet;

fn is_string_contain_identical_digits(s: &str) -> bool {
    let set: HashSet<_> = s.chars().collect();
    
    set.len() == 1
}

fn main() {
    let str = "8888888";

    if is_string_contain_identical_digits(str) {
        println!("yes");
    } else {
        println!("no");
    }
}




/*
run:

yes

*/

 



answered Jul 24, 2024 by avibootz

Related questions

1 answer 109 views
1 answer 115 views
1 answer 106 views
1 answer 111 views
1 answer 131 views
1 answer 113 views
1 answer 123 views
...