-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3206.go
More file actions
40 lines (32 loc) · 946 Bytes
/
solution3206.go
File metadata and controls
40 lines (32 loc) · 946 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
package solution3206
// ============================================================================
// 3206. Alternating Groups I
// URL: https://leetcode.com/problems/alternating-groups-i/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3206---Alternating-Groups-I
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
BenchmarkNumberOfAlternatingGroups
BenchmarkNumberOfAlternatingGroups-24 100000000 15.05 ns/op 0 B/op 0 allocs/op
PASS
*/
func numberOfAlternatingGroups(colors []int) int {
var a, b, c, n int
for i := 0; i < len(colors); i++ {
a = i
b = i + 1
c = i + 2
if b >= len(colors) {
b = i - len(colors) + 1
}
if c >= len(colors) {
c = i - len(colors) + 2
}
if colors[a] == 1 && colors[b] == 0 && colors[c] == 1 || colors[a] == 0 && colors[b] == 1 && colors[c] == 0 {
n++
}
}
return n
}