add new solutions
This commit is contained in:
parent
ee1868a10e
commit
2012261d3d
7 changed files with 205 additions and 0 deletions
27
solutions/14/q1461/solution.go
Normal file
27
solutions/14/q1461/solution.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package q1461
|
||||
|
||||
func hasAllCodes(s string, k int) bool {
|
||||
if len(s) < (1<<k)+k-1 {
|
||||
return false
|
||||
}
|
||||
seen := make([]bool, 1<<k)
|
||||
nSeen := 0
|
||||
|
||||
c := 0
|
||||
for i := range len(s) {
|
||||
c = (c << 1) + int(s[i]-'0')
|
||||
if i+1 >= k {
|
||||
if i >= k {
|
||||
c -= int(s[i-k]-'0') << k
|
||||
}
|
||||
|
||||
if !seen[c] {
|
||||
seen[c] = true
|
||||
nSeen++
|
||||
}
|
||||
}
|
||||
}
|
||||
return nSeen == 1<<k
|
||||
}
|
||||
|
||||
var _ = hasAllCodes
|
||||
Loading…
Add table
Add a link
Reference in a new issue