Last active
November 13, 2023 15:58
-
-
Save diaasami/4a434d7b204582cf8635dea3e378de26 to your computer and use it in GitHub Desktop.
LeetCode - 1461. Check If a String Contains All Binary Codes of Size K
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def hasAllCodes(self, s: str, k: int) -> bool: | |
| num_perms = math.pow(2, k) | |
| substrings_of_len_k = len(s) - k + 1 | |
| if substrings_of_len_k < num_perms: | |
| return False | |
| perms = set() | |
| for i in range(k, len(s)+1): | |
| perms.add(s[i-k:i]) | |
| return len(perms) == num_perms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment