rs: add “1704. Determine if String Halves Are Alike”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
9cfd3567be
commit
fee07aaed3
1 changed files with 17 additions and 0 deletions
17
rs/determine-if-string-halves-are-alike.rs
Normal file
17
rs/determine-if-string-halves-are-alike.rs
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue