mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-25 03:11:41 +08:00
19 lines
233 B
Go
19 lines
233 B
Go
package leetcode
|
|
|
|
func minOperations(s string) int {
|
|
res := 0
|
|
for i := 0; i < len(s); i++ {
|
|
if int(s[i]-'0') != i%2 {
|
|
res++
|
|
}
|
|
}
|
|
return min(res, len(s)-res)
|
|
}
|
|
|
|
func min(a, b int) int {
|
|
if a > b {
|
|
return b
|
|
}
|
|
return a
|
|
}
|