add new solutions
This commit is contained in:
parent
0f5f9e331c
commit
a7ff717b7a
7 changed files with 221 additions and 0 deletions
15
solutions/6/q693/solution.go
Normal file
15
solutions/6/q693/solution.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package q693
|
||||
|
||||
func hasAlternatingBits(n int) bool {
|
||||
last := -1
|
||||
for n > 0 {
|
||||
if last == n%2 {
|
||||
return false
|
||||
}
|
||||
last = n % 2
|
||||
n >>= 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var _ = hasAlternatingBits
|
||||
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