-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3208.java
28 lines (27 loc) · 911 Bytes
/
_3208.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
27
28
package com.fishercoder.solutions.fourththousand;
public class _3208 {
public static class Solution1 {
/*
* My completely original solution:
* we just keep looking for the possible k alternating groups, if it encounters the same color, then set i to that pointer and restart.
*/
public int numberOfAlternatingGroups(int[] colors, int k) {
int len = colors.length;
int groups = 0;
int i = 0;
for (; i < len; i++) {
int j = i + 1;
for (; j < len + k - 1; j++) {
if (colors[j % len] == colors[(j - 1) % len]) {
break;
}
if (j - i + 1 >= k) {
groups++;
}
}
i = j - 1;
}
return groups;
}
}
}