Skip to content

Commit fcf2f3f

Browse files
authored
Create 1461-check-if-a-string-contains-all-binary-codes-of-size-k.js
1 parent d908f88 commit fcf2f3f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {string} s
3+
* @param {number} k
4+
* @return {boolean}
5+
*/
6+
const hasAllCodes = function (s, k) {
7+
if (s.length < k) return false
8+
const set = new Set()
9+
for (let i = 0; i <= s.length - k; i++) {
10+
set.add(s.slice(i, i + k))
11+
}
12+
13+
return set.size == Math.pow(2, k)
14+
}

0 commit comments

Comments
 (0)