Skip to content

Commit eb2a473

Browse files
authored
Add Check If a String Contains All Binary Codes of Size K.java
1 parent c8433f6 commit eb2a473

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean hasAllCodes(String s, int k) {
3+
Set<String> set = new HashSet<>();
4+
int counter = 1 << k;
5+
for (int i = k; i <= s.length(); i++) {
6+
String temp = s.substring(i - k, i);
7+
if (!set.contains(temp)) {
8+
set.add(temp);
9+
counter--;
10+
}
11+
if (counter == 0) {
12+
return true;
13+
}
14+
}
15+
return false;
16+
}
17+
}

0 commit comments

Comments
 (0)