diff options
Diffstat (limited to 'determine_string_halves.rs')
-rw-r--r-- | determine_string_halves.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/determine_string_halves.rs b/determine_string_halves.rs new file mode 100644 index 0000000..f7f4303 --- /dev/null +++ b/determine_string_halves.rs @@ -0,0 +1,18 @@ +use std::collections::HashSet; +struct Solution; + +impl Solution { + pub fn halves_are_alike(s: String) -> bool { + let vowels: HashSet<char> = HashSet::from(['a','e','i','o','u','A','E','I','O','U']); + s.chars() + .enumerate() + .filter(|(_, c)| vowels.contains(c)) + .map(|(i, _)| (s.len() as i32 - 2 * (i as i32) - 1).signum()) + .sum::<i32>() == 0 + } +} + +fn main() { + let s = String::from("book"); + print!("{}", Solution::halves_are_alike(s)); +} |