Skip to content

Commit 7171203

Browse files
committed
Runtime: 13 ms (Top 52.13%) | Memory: 6.10 MB (Top 92.55%)
1 parent 23f7ba4 commit 7171203

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Runtime: 13 ms (Top 52.13%) | Memory: 6.10 MB (Top 92.55%)
2+
3+
func winnerOfGame(colors string) bool {
4+
countA := 0
5+
countB := 0
6+
7+
for i := 0; i < len(colors); i++ {
8+
x := colors[i]
9+
count := 0
10+
11+
for i < len(colors) && colors[i] == x {
12+
i++
13+
count++
14+
}
15+
16+
if x == 'A' {
17+
countA += max(count-2, 0)
18+
} else if x == 'B' {
19+
countB += max(count-2, 0)
20+
}
21+
22+
i--
23+
}
24+
25+
return countA > countB
26+
}
27+
28+
func max(a, b int) int {
29+
if a > b {
30+
return a
31+
}
32+
return b
33+
}
34+

0 commit comments

Comments
 (0)