mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
Add solution 0368、0377、0696
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user