-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3206.java
26 lines (25 loc) · 870 Bytes
/
_3206.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.fishercoder.solutions.fourththousand;
public class _3206 {
public static class Solution1 {
public int numberOfAlternatingGroups(int[] colors) {
int result = 0;
int len = colors.length;
for (int i = 0; i < len; i++) {
if (i == 0) {
if (colors[i] != colors[len - 1] && colors[i] != colors[i + 1]) {
result++;
}
} else if (i < len - 1) {
if (colors[i] != colors[i - 1] && colors[i] != colors[i + 1]) {
result++;
}
} else {
if (colors[i] != colors[i - 1] && colors[i] != colors[0]) {
result++;
}
}
}
return result;
}
}
}