mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-06-04 02:21:15 +08:00
17 lines
211 B
Go
17 lines
211 B
Go
package main
|
|
|
|
func minOperations(s string) int {
|
|
a := 0
|
|
for i := 0; i < len(s); i++ {
|
|
expected := byte('0' + i%2)
|
|
if s[i] == expected {
|
|
a++
|
|
}
|
|
}
|
|
b := len(s) - a
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|