#3206
Alternating Groups I
pupil · 305 · lc easy +21 · 68.8% accepted · 169 likes · top 76%
Description
A circle of tiles is colored red or blue. You are given integer array colors where colors[i] == 0 means red and colors[i] == 1 means blue.
Three consecutive circular tiles form an alternating group when the middle tile's color differs from both its neighbors.
Return the count of alternating groups. The first and last tiles are adjacent (circular).
Code
1
2
3