Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 55ac67f

Browse files
committedMar 31, 2025
Add solution #1016
1 parent af93ee5 commit 55ac67f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,090 LeetCode solutions in JavaScript
1+
# 1,091 LeetCode solutions in JavaScript
22

33
[https://leetcode.com/](https://leetcode.com/)
44

@@ -824,6 +824,7 @@
824824
1013|[Partition Array Into Three Parts With Equal Sum](./solutions/1013-partition-array-into-three-parts-with-equal-sum.js)|Easy|
825825
1014|[Best Sightseeing Pair](./solutions/1014-best-sightseeing-pair.js)|Medium|
826826
1015|[Smallest Integer Divisible by K](./solutions/1015-smallest-integer-divisible-by-k.js)|Medium|
827+
1016|[Binary String With Substrings Representing 1 To N](./solutions/1016-binary-string-with-substrings-representing-1-to-n.js)|Medium|
827828
1022|[Sum of Root To Leaf Binary Numbers](./solutions/1022-sum-of-root-to-leaf-binary-numbers.js)|Easy|
828829
1023|[Camelcase Matching](./solutions/1023-camelcase-matching.js)|Medium|
829830
1028|[Recover a Tree From Preorder Traversal](./solutions/1028-recover-a-tree-from-preorder-traversal.js)|Hard|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 1016. Binary String With Substrings Representing 1 To N
3+
* https://leetcode.com/problems/binary-string-with-substrings-representing-1-to-n/
4+
* Difficulty: Medium
5+
*
6+
* Given a binary string s and a positive integer n, return true if the binary representation of
7+
* all the integers in the range [1, n] are substrings of s, or false otherwise.
8+
*
9+
* A substring is a contiguous sequence of characters within a string.
10+
*/
11+
12+
/**
13+
* @param {string} s
14+
* @param {number} n
15+
* @return {boolean}
16+
*/
17+
var queryString = function(binaryString, maxNumber) {
18+
return hasAllSubstrings(binaryString, maxNumber);
19+
20+
function hasAllSubstrings(str, num) {
21+
for (let i = 1; i <= num; i++) {
22+
if (!str.includes(i.toString(2))) return false;
23+
}
24+
return true;
25+
}
26+
};

0 commit comments

Comments
 (0)
Please sign in to comment.