-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
41 lines (35 loc) · 993 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Arrays;
// class Solution {
// public List<Boolean> prefixesDivBy5(int[] A) {
// int n = A.length;
// long cur = 0;
// List<Boolean> list = new ArrayList<Boolean>();
// for (int i = 0; i < n; i++) {
// if (i == 0) {
// cur = A[0];
// } else {
// cur <<= 1;
// cur += A[i];
// }
// list.add(cur % 5 == 0);
// cur %= 5;
// }
// return list;
// }
// }
class Solution {
public List<Boolean> prefixesDivBy5(int[] A) {
int n = A.length;
int cur = 0;
Boolean[] list = new Boolean[n];
Arrays.fill(list, false);
for (int i = 0; i < n; i++) {
cur = cur * 2 + A[i];
if (cur % 5 == 0) {
list[i] = true;
}
cur %= 5;
}
return Arrays.asList(list);
}
}