20250107 finished.
This commit is contained in:
parent
f2c5afba21
commit
99aaf987df
|
@ -416,3 +416,5 @@ mod p732_my_calendar_iii;
|
||||||
mod p2241_design_an_atm_machine;
|
mod p2241_design_an_atm_machine;
|
||||||
|
|
||||||
mod p2274_maximum_consecutive_floors_without_special_floors;
|
mod p2274_maximum_consecutive_floors_without_special_floors;
|
||||||
|
|
||||||
|
mod p3019_number_of_changing_keys;
|
||||||
|
|
37
src/problem/p3019_number_of_changing_keys.rs
Normal file
37
src/problem/p3019_number_of_changing_keys.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* [3019] Number of Changing Keys
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn count_key_changes(s: String) -> i32 {
|
||||||
|
let mut second_chars = s.chars();
|
||||||
|
second_chars.next();
|
||||||
|
|
||||||
|
second_chars
|
||||||
|
.zip(s.chars())
|
||||||
|
.filter_map(|(a, b)| {
|
||||||
|
if a.to_lowercase().next() != b.to_lowercase().next() {
|
||||||
|
Some(())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.count() as i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_3019() {
|
||||||
|
assert_eq!(2, Solution::count_key_changes("aAbBcC".to_owned()));
|
||||||
|
assert_eq!(0, Solution::count_key_changes("AaAaAaaA".to_owned()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user