Skip to content

Instantly share code, notes, and snippets.

@sabman
Forked from wunki/unique_chars.rs
Last active December 29, 2020 16:59
Show Gist options
  • Save sabman/4d9576c612836e176a12b200a3e57c87 to your computer and use it in GitHub Desktop.
Save sabman/4d9576c612836e176a12b200a3e57c87 to your computer and use it in GitHub Desktop.
Unique character check in Rust
use std::os;
fn unique_chars(s: &str) -> bool {
let v: Vec<char> = s.chars().collect();
let mut y = v.clone();
y.sort();
y.dedup();
v.len() == y.len()
}
fn main() -> () {
let args = os::args();
let sentence = args.get(1);
match unique_chars(sentence.as_slice()) {
true => println!("String contains only unique characters"),
false => println!("String doesn't contain only unique characters")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment