20241126 finished.
This commit is contained in:
parent
6c9151aa2c
commit
e39de1ba66
|
@ -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;
|
||||||
|
|
42
src/problem/p3206_alternating_groups_i.rs
Normal file
42
src/problem/p3206_alternating_groups_i.rs
Normal 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])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user