Binary String With Substrings Representing 1 To N
You can solve this problem by iterating through the range of numbers from 1 to n, and for each number, you need to check whether its binary representation is a substring of the given string s
.
Here’s the Python code:
|
|
Explanation:
- We use a for loop to iterate through numbers from 1 to n.
- For each number, we convert it to its binary representation using the
bin
function, and then we check whether this binary representation is a substring ofs
using thein
keyword. - If we find any number whose binary representation is not a substring of
s
, we returnFalse
. - If all binary representations are substrings of
s
, we returnTrue
.