Skip to content

Commit d92587c

Browse files
authored
Create 3208. Alternating Groups II
1 parent 23292fb commit d92587c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

3208. Alternating Groups II

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int numberOfAlternatingGroups(vector<int>& colors, int k) {
4+
int ans = 0, cnt = 1, n = colors.size();
5+
for(int i = 1; i < (n + k - 1); i++) {
6+
if(colors[i % n] != colors[(i - 1) % n]) {
7+
cnt++;
8+
}
9+
else cnt = 1;
10+
if(cnt >= k) ans++;
11+
}
12+
return ans;
13+
}
14+
};

0 commit comments

Comments
 (0)