Created
October 4, 2019 22:07
-
-
Save damienstanton/0334f93e46862fb552adc7387fe5407d to your computer and use it in GitHub Desktop.
string is unique
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
pub fn str_is_unique(s: &str) -> bool { | |
let mut map: HashMap<char, i32> = HashMap::new(); | |
for c in s.chars() { | |
*map.entry(c).or_insert(0) += 1; | |
} | |
!map.iter().any(|(_, &v)| v > 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment