Skip to content

Commit 5fa5dea

Browse files
authored
Create 3208. Alternating Groups II (#735)
2 parents 23292fb + d92587c commit 5fa5dea

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)