mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-12 22:55:19 +08:00
add: leetcode 2038 solution
This commit is contained in:
@ -0,0 +1,25 @@
|
|||||||
|
package leetcode
|
||||||
|
|
||||||
|
func winnerOfGame(colors string) bool {
|
||||||
|
As, Bs := 0, 0
|
||||||
|
Acont, Bcont := 0, 0
|
||||||
|
for _, color := range colors {
|
||||||
|
if color == 'A' {
|
||||||
|
Acont += 1
|
||||||
|
Bcont = 0
|
||||||
|
} else {
|
||||||
|
Bcont += 1
|
||||||
|
Acont = 0
|
||||||
|
}
|
||||||
|
if Acont >= 3 {
|
||||||
|
As += Acont - 2
|
||||||
|
}
|
||||||
|
if Bcont >= 3 {
|
||||||
|
Bs += Bcont - 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if As > Bs {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
Reference in New Issue
Block a user