add new solutions
This commit is contained in:
parent
f249852923
commit
f297e11859
10 changed files with 373 additions and 0 deletions
19
solutions/17/q1758/solution.go
Normal file
19
solutions/17/q1758/solution.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue