20241126 finished.

This commit is contained in:
jackfiled 2024-11-26 14:04:11 +08:00
parent 6c9151aa2c
commit e39de1ba66
2 changed files with 44 additions and 0 deletions

View File

@ -336,3 +336,5 @@ mod p3233_find_the_count_of_numbers_which_are_not_special;
mod p3238_find_the_number_of_winning_players; mod p3238_find_the_number_of_winning_players;
mod p632_smallest_range_covering_elements_from_k_lists; mod p632_smallest_range_covering_elements_from_k_lists;
mod p3206_alternating_groups_i;

View File

@ -0,0 +1,42 @@
/**
* [3206] Alternating Groups I
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn number_of_alternating_groups(colors: Vec<i32>) -> i32 {
let n = colors.len();
let mut result = 0;
for i in n..2 * n {
let left = (i - 1) % n;
let middle = i % n;
let right = (i + 1) % n;
if colors[left] != colors[middle] && colors[right] != colors[middle] {
result += 1;
}
}
result
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_3206() {
assert_eq!(0, Solution::number_of_alternating_groups(vec![0, 0, 0]));
assert_eq!(
3,
Solution::number_of_alternating_groups(vec![0, 1, 0, 0, 1])
);
}
}