Check If a String Contains All Binary Codes of Size K LeetCode solution in Java

1
class Solution {
2
public boolean hasAllCodes(String s, int k) {
3
HashSet<String> hs = new HashSet();
4
for (int i = 0; i <= s.length() - k; i++) {
5
hs.add(s.substring(i, i + k));
6
}
7
if (hs.size() == Math.pow(2, k)) return true;
8
return false;
9
}
10
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0