Skip to content

Commit bf4cabf

Browse files
3208_Alternating_Groups_II.java
1 parent 16aafb2 commit bf4cabf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

JAVA/3208_Alternating_Groups_II.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Problem Number: 3208
2+
3+
// Alternating Groups II
4+
5+
class Solution {
6+
public int numberOfAlternatingGroups(int[] colors, int k) {
7+
final int n=colors.length;
8+
int alternating=1;
9+
int ans=0;
10+
11+
for(int i=0; i<n+k-2; i++){
12+
alternating= colors[i%n]==colors[(i-1+n)%n]?1:alternating+1;
13+
if(alternating>=k){
14+
ans++;
15+
}
16+
17+
}
18+
19+
return ans;
20+
21+
}
22+
}

0 commit comments

Comments
 (0)