Files
LeetCode-Go/leetcode/0696.Count-Binary-Substrings/696. Count Binary Substrings.go
2021-04-24 21:04:28 +08:00

22 lines
308 B
Go

package leetcode
func countBinarySubstrings(s string) int {
last, res := 0, 0
for i := 0; i < len(s); {
c, count := s[i], 1
for i++; i < len(s) && s[i] == c; i++ {
count++
}
res += min(count, last)
last = count
}
return res
}
func min(a, b int) int {
if a < b {
return a
}
return b
}