LeetCode 1461. Check If a String Contains All Binary Codes of Size K in F#
URL
leetcode.com/problems/check-if-a-string-con..
Code
github.com/syohex/dotnet-study/blob/master/..
open System
let hasAllCodes (s: string) (k: int) : bool =
if s.Length < k then
false
else
let sets =
seq { 0 .. (s.Length - k) }
|> Seq.map (fun i -> s.Substring(i, k))
|> Seq.fold (fun acc s -> Set.add s acc) Set.empty
sets.Count = (Math.Pow(2, k) |> int)