Skip to content

Instantly share code, notes, and snippets.

@damienstanton
Created October 4, 2019 22:07
Show Gist options
  • Save damienstanton/0334f93e46862fb552adc7387fe5407d to your computer and use it in GitHub Desktop.
Save damienstanton/0334f93e46862fb552adc7387fe5407d to your computer and use it in GitHub Desktop.
string is unique
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