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 190 views
1 answer 197 views
1 answer 203 views
1 answer 196 views
1 answer 219 views
1 answer 192 views
1 answer 251 views
...