lc-go/solutions/17/q1758/solution.go
2026-03-13 16:18:54 +09:00

19 lines
346 B
Go

// Package q1758 implements a solution for https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/
package q1758
func minOperations(s string) int {
a, b := 0, 0
var alt byte = 1
for i := range len(s) {
if s[i]-'0' == alt {
a++
} else {
b++
}
alt = alt ^ 1
}
return min(a, b)
}
var _ = minOperations