20250107 finished.

This commit is contained in:
jackfiled 2025-01-07 12:14:14 +08:00
parent f2c5afba21
commit 99aaf987df
2 changed files with 39 additions and 0 deletions

View File

@ -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;

View 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()));
}
}