1461. Check If a String Contains All Binary Codes of Size K Medium
1/**
2 * [1461] Check If a String Contains All Binary Codes of Size K
3 *
4 * Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.
5 *
6 * Example 1:
7 *
8 * Input: s = "00110110", k = 2
9 * Output: true
10 * Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indices 0, 1, 3 and 2 respectively.
11 *
12 * Example 2:
13 *
14 * Input: s = "0110", k = 1
15 * Output: true
16 * Explanation: The binary codes of length 1 are "0" and "1", it is clear that both exist as a substring.
17 *
18 * Example 3:
19 *
20 * Input: s = "0110", k = 2
21 * Output: false
22 * Explanation: The binary code "00" is of length 2 and does not exist in the array.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= s.length <= 5 * 10^5
28 * s[i] is either '0' or '1'.
29 * 1 <= k <= 20
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/
35// discuss: https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn has_all_codes(s: String, k: i32) -> bool {
41 false
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1461() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.