check-if-a-string-contains-all-binary-codes-of-size-k

This commit is contained in:
Gleb Koval 2022-05-31 20:04:54 +01:00
parent 2fc684641f
commit 5a1d509d09
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,10 @@
use std::collections::HashSet;
impl Solution {
pub fn has_all_codes(s: String, k: i32) -> bool {
s.into_bytes()
.windows(k as usize)
.collect::<HashSet<_>>()
.len() == 1 << k
}
}