21 lines
400 B
Go
21 lines
400 B
Go
// Package q696 implements a solution for https://leetcode.com/problems/count-binary-substrings/
|
|
package q696
|
|
|
|
func countBinarySubstrings(s string) int {
|
|
cnt := 0
|
|
last := byte('0')
|
|
lastLen, curLen := 0, 0
|
|
for i := range len(s) {
|
|
if s[i] != last {
|
|
last, lastLen = s[i], curLen
|
|
curLen = 0
|
|
}
|
|
curLen++
|
|
if curLen <= lastLen {
|
|
cnt++
|
|
}
|
|
}
|
|
return cnt
|
|
}
|
|
|
|
var _ = countBinarySubstrings
|