File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,313 LeetCode solutions in JavaScript
1+ # 1,314 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
111611161457|[ Pseudo-Palindromic Paths in a Binary Tree] ( ./solutions/1457-pseudo-palindromic-paths-in-a-binary-tree.js ) |Medium|
111711171458|[ Max Dot Product of Two Subsequences] ( ./solutions/1458-max-dot-product-of-two-subsequences.js ) |Hard|
111811181460|[ Make Two Arrays Equal by Reversing Sub-arrays] ( ./solutions/1460-make-two-arrays-equal-by-reversing-sub-arrays.js ) |Easy|
1119+ 1461|[ Check If a String Contains All Binary Codes of Size K] ( ./solutions/1461-check-if-a-string-contains-all-binary-codes-of-size-k.js ) |Medium|
111911201462|[ Course Schedule IV] ( ./solutions/1462-course-schedule-iv.js ) |Medium|
112011211464|[ Maximum Product of Two Elements in an Array] ( ./solutions/1464-maximum-product-of-two-elements-in-an-array.js ) |Easy|
112111221466|[ Reorder Routes to Make All Paths Lead to the City Zero] ( ./solutions/1466-reorder-routes-to-make-all-paths-lead-to-the-city-zero.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1461. Check If a String Contains All Binary Codes of Size K
3+ * https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/
4+ * Difficulty: Medium
5+ *
6+ * Given a binary string s and an integer k, return true if every binary code of length k is a
7+ * substring of s. Otherwise, return false.
8+ */
9+
10+ /**
11+ * @param {string } s
12+ * @param {number } k
13+ * @return {boolean }
14+ */
15+ var hasAllCodes = function ( s , k ) {
16+ const requiredCount = 1 << k ;
17+ const seenCodes = new Set ( ) ;
18+
19+ for ( let i = 0 ; i <= s . length - k ; i ++ ) {
20+ seenCodes . add ( s . slice ( i , i + k ) ) ;
21+ if ( seenCodes . size === requiredCount ) return true ;
22+ }
23+
24+ return false ;
25+ } ;
You can’t perform that action at this time.
0 commit comments