1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| // @Title: 如果相邻两个颜色均相同则删除当前颜色 (Remove Colored Pieces if Both Neighbors are the Same Color)
// @Author: 15816537946@163.com
// @Date: 2022-03-22 20:20:24
// @Runtime: 12 ms
// @Memory: 6.2 MB
func winnerOfGame(colors string) bool {
freq := [2]int{}
cur, cnt := 'C', 0
for _, c := range colors {
if c != cur {
cur, cnt = c, 1
} else {
cnt++
if cnt >= 3 {
freq[cur-'A']++
}
}
}
return freq[0] > freq[1]
}
|