|
3 | 3 | importjava.util.ArrayList;
|
4 | 4 | importjava.util.List;
|
5 | 5 |
|
6 |
| -/** |
7 |
| - * 1018. Binary Prefix Divisible By 5 |
8 |
| - * |
9 |
| - * Given an array A of 0s and 1s, consider N_i: the i-th subarray from A[0] to A[i] interpreted as a binary number (from most-significant-bit to least-significant-bit.) |
10 |
| - * |
11 |
| - * Return a list of booleans answer, where answer[i] is true if and only if N_i is divisible by 5. |
12 |
| - * |
13 |
| - * Example 1: |
14 |
| - * |
15 |
| - * Input: [0,1,1] |
16 |
| - * Output: [true,false,false] |
17 |
| - * Explanation: |
18 |
| - * 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[0] is true. |
19 |
| - * Example 2: |
20 |
| - * |
21 |
| - * Input: [1,1,1] |
22 |
| - * Output: [false,false,false] |
23 |
| - * Example 3: |
24 |
| - * |
25 |
| - * Input: [0,1,1,1,1,1] |
26 |
| - * Output: [true,false,false,false,true,false] |
27 |
| - * Example 4: |
28 |
| - * |
29 |
| - * Input: [1,1,1,0,1] |
30 |
| - * Output: [false,false,false,false,false] |
31 |
| - * |
32 |
| - * |
33 |
| - * Note: |
34 |
| - * |
35 |
| - * 1 <= A.length <= 30000 |
36 |
| - * A[i] is 0 or 1 |
37 |
| - * */ |
38 | 6 | publicclass_1018 {
|
39 | 7 | publicstaticclassSolution1 {
|
40 |
| -/**credit: https://leetcode.com/problems/binary-prefix-divisible-by-5/discuss/266051/Java-beats-100*/ |
| 8 | +/** |
| 9 | + * credit: https://leetcode.com/problems/binary-prefix-divisible-by-5/discuss/266051/Java-beats-100 |
| 10 | + */ |
41 | 11 | publicList<Boolean>prefixesDivBy5(int[]A) {
|
42 | 12 | List<Boolean>result =newArrayList<>(A.length);
|
43 | 13 | intremainder =0;
|
|