1016. Binary String With Substrings Representing 1 To N

Difficulty:
Related Topics:
Similar Questions:

    Problem

    Given a binary string s and a positive integer n, return true** if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise**.

    A substring is a contiguous sequence of characters within a string.

      Example 1:

    Input: s = "0110", n = 3
    Output: true
    

    Example 2:

    Input: s = "0110", n = 4
    Output: false
    

      Constraints:

    Solution (Java)

    class Solution {
        public boolean queryString(String s, int n) {
            for (int i = 1; i <= n; i++) {
                String str = Integer.toBinaryString(i);
                if (!s.contains(str)) {
                    return false;
                }
            }
            return true;
        }
    }
    

    Explain:

    nope.

    Complexity: