LeetCode solutions

1065. Binary String With Substrings Representing 1 To N

My accepted Python solution to LeetCode problem 1065, Binary String With Substrings Representing 1 To N, running in 0ms.

  • Difficulty: Medium
  • Python
  • Runtime 0ms
  • Memory 17.5MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.5MB, accepted 2026-01-02.

python
class Solution:
    def queryString(self, s: str, n: int) -> bool:
        # Check each number from 1 to n
        for i in range(1, n + 1):
            if bin(i)[2:] not in s:
                return False
        return True

Source