@@ -0,0 +1,1218 @@
+package bit_operation;%0A%0Apublic class Q1023BinaryStringWithSubstringsRepresenting1ToN %7B%0A%0A    //Difficulty: medium%0A    //TAG: bit operation%0A%0A    /**%0A     * 1023. Binary String With Substrings Representing 1 To N%0A     * Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return true if and only if for every integer X from 1 to N, the binary representation of X is a substring of S.%0A     *%0A     *%0A     *%0A     * Example 1:%0A     *%0A     * Input: S = %220110%22, N = 3%0A     * Output: true%0A     * Example 2:%0A     *%0A     * Input: S = %220110%22, N = 4%0A     * Output: false%0A     *%0A     *%0A     * Note:%0A     *%0A     * 1 %3C= S.length %3C= 1000%0A     * 1 %3C= N %3C= 10%5E9%0A     */%0A%0A    /*%0A    Solution:%0A    check from N to N / 2 see if any converted binary string is substring of S%0A%0A    Time: O(S%5E2)%0A    Space: O(1)%0A     */%0A%0A    public boolean queryString(String S, int N) %7B%0A        /*%0A        due to for N binary string XXXXX, 2*N binary string is 1XXXXX, so if S contains 2 * N, then S must contains S%0A        we just need check from N to N/2%0A         */%0A        for (int i = N; i %3E= N/2; i--) %7B%0A            if (!S.contains(Integer.toBinaryString(i))) return false;%0A        %7D%0A        return true;%0A    %7D%0A%0A%7D%0A

1023. Binary String With Substrings Representing 1 To N