Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfff4dab

Browse files
authored
Create 1461-check-if-a-string-contains-all-binary-codes-of-size-k.js
Added a solution for check-if-a-string-contains-all-binary-codes-of-size-k in JS.
1 parent9d668c6 commitfff4dab

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/
3+
*
4+
* Hashing
5+
* Time O(n*k) | Space O(2^k) (it can't get any bigger than 2^k in the worst case)
6+
*@param {string} s
7+
*@param {number} k
8+
*@return {boolean}
9+
*/
10+
varhasAllCodes=function(s,k){
11+
12+
constbitSet=newSet();
13+
14+
for(leti=0;i<s.length;i++){
15+
if(s.substring(i,i+k).length===k){
16+
bitSet.add(s.substring(i,i+k));
17+
}
18+
}
19+
20+
returnbitSet.size===1<<k;
21+
};
22+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp