From 5a1d509d09976762529dd9bfc6e6a4c2b737a311 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Tue, 31 May 2022 20:04:54 +0100 Subject: [PATCH] check-if-a-string-contains-all-binary-codes-of-size-k --- .../sol.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 check-if-a-string-contains-all-binary-codes-of-size-k/sol.rs diff --git a/check-if-a-string-contains-all-binary-codes-of-size-k/sol.rs b/check-if-a-string-contains-all-binary-codes-of-size-k/sol.rs new file mode 100644 index 0000000..59e969c --- /dev/null +++ b/check-if-a-string-contains-all-binary-codes-of-size-k/sol.rs @@ -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::>() + .len() == 1 << k + } +} \ No newline at end of file