Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 581 Bytes

Question_1461.md

File metadata and controls

21 lines (17 loc) · 581 Bytes

LeetCode Records - Question 1461 Check If a String Contains All Binary Codes of Size K

Attempt 1: Use a HashSet to store all the substrings with the k length

class Solution {
    public boolean hasAllCodes(String s, int k) {
        Set<String> set = new HashSet<>();

        int len = s.length();
        for (int i = 0; i < len - k + 1; i++) {
            set.add(s.substring(i, i + k));
        }
        
        return set.size() == (int)Math.pow(2, k);
    }
}
  • Runtime: 164 ms (Beats: 53.74%)
  • Memory: 67.84 MB (Beats: 77.28%)