@@ -0,0 +1,1563 @@
+package math.binary;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class Q1018BinaryPrefixDivisibleBy5 %7B%0A%0A    /**%0A     * 1018. Binary Prefix Divisible By 5%0A     * Given an array A of 0s and 1s, consider N_i: the i-th subarray from A%5B0%5D to A%5Bi%5D interpreted as a binary number (from most-significant-bit to least-significant-bit.)%0A     *%0A     * Return a list of booleans answer, where answer%5Bi%5D is true if and only if N_i is divisible by 5.%0A     *%0A     * Example 1:%0A     *%0A     * Input: %5B0,1,1%5D%0A     * Output: %5Btrue,false,false%5D%0A     * Explanation:%0A     * The input numbers in binary are 0, 01, 011; which are 0, 1, and 3 in base-10.  Only the first number is divisible by 5, so answer%5B0%5D is true.%0A     * Example 2:%0A     *%0A     * Input: %5B1,1,1%5D%0A     * Output: %5Bfalse,false,false%5D%0A     * Example 3:%0A     *%0A     * Input: %5B0,1,1,1,1,1%5D%0A     * Output: %5Btrue,false,false,false,true,false%5D%0A     * Example 4:%0A     *%0A     * Input: %5B1,1,1,0,1%5D%0A     * Output: %5Bfalse,false,false,false,false%5D%0A     *%0A     *%0A     * Note:%0A     *%0A     * 1 %3C= A.length %3C= 30000%0A     * A%5Bi%5D is 0 or 1%0A     */%0A%0A    /*%0A    Solution:%0A%0A    n %25 5 == n %3C%3C 1 %25 5%0A    so n %3C%3C 1 + digit = (n%255)%3C%3C1 + digit%0A%0A    every time when n = n %3C%3C 1 + digit then n %25= 5, check if n == 0%0A%0A    Time: O(n)%0A    Space: O(n)%0A     */%0A%0A    public List%3CBoolean%3E prefixesDivBy5(int%5B%5D A) %7B%0A        List%3CBoolean%3E list = new ArrayList%3C%3E();%0A        int num = 0;%0A        for (int cur: A) %7B%0A            num = (num %3C%3C 1) + cur;%0A            num %25= 5;%0A            list.add(num == 0);%0A        %7D%0A        return list;%0A    %7D%0A%0A%7D%0A

1018. Binary Prefix Divisible By 5