3206. Alternating Groups I Easy
1/**
2 * [3206] Alternating Groups I
3 *
4 * There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]:
5 *
6 * colors[i] == 0 means that tile i is red.
7 * colors[i] == 1 means that tile i is blue.
8 *
9 * Every 3 contiguous tiles in the circle with alternating colors (the middle tile has a different color from its left and right tiles) is called an alternating group.
10 * Return the number of alternating groups.
11 * Note that since colors represents a circle, the first and the last tiles are considered to be next to each other.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">colors = [1,1,1]</span>
16 * Output: <span class="example-io">0</span>
17 * Explanation:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-53-171.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" />
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">colors = [0,1,0,0,1]</span>
23 * Output: 3
24 * Explanation:
25 * <img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-47-491.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" />
26 * Alternating groups:
27 * <strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-50-441.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-48-211.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-49-351.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" />
28 * </div>
29 *
30 * Constraints:
31 *
32 * 3 <= colors.length <= 100
33 * 0 <= colors[i] <= 1
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/alternating-groups-i/
39// discuss: https://leetcode.com/problems/alternating-groups-i/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn number_of_alternating_groups(colors: Vec<i32>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3206() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.