add new solutions

This commit is contained in:
Yiyang Kang 2026-03-01 13:45:00 +09:00
parent ee1868a10e
commit 2012261d3d
7 changed files with 205 additions and 0 deletions

View 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