From fee07aaed360ca51204a8ef46c2f6b2e280e5360 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 12 Jan 2024 12:21:50 +0100 Subject: [PATCH] =?UTF-8?q?rs:=20add=20=E2=80=9C1704.=20Determine=20if=20S?= =?UTF-8?q?tring=20Halves=20Are=20Alike=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- rs/determine-if-string-halves-are-alike.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 rs/determine-if-string-halves-are-alike.rs diff --git a/rs/determine-if-string-halves-are-alike.rs b/rs/determine-if-string-halves-are-alike.rs new file mode 100644 index 0000000..4301fd6 --- /dev/null +++ b/rs/determine-if-string-halves-are-alike.rs @@ -0,0 +1,17 @@ +impl Solution { + fn get_vowels(s: &str) -> usize { + s.to_lowercase() + .chars() + .filter_map(|c| match c { + 'a' | 'e' | 'i' | 'o' | 'u' => Some(c), + _ => None, + }) + .count() + } + + pub fn halves_are_alike(s: String) -> bool { + let (a, b) = s.split_at(s.len() / 2); + + Solution::get_vowels(a) == Solution::get_vowels(b) + } +}