add new solutions
This commit is contained in:
parent
0f5f9e331c
commit
a7ff717b7a
7 changed files with 221 additions and 0 deletions
20
solutions/6/q696/solution.go
Normal file
20
solutions/6/q696/solution.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue