mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
22 lines
308 B
Go
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
|
|
}
|