- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1018.java
21 lines (19 loc) · 628 Bytes
/
_1018.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_1018 {
publicstaticclassSolution1 {
/*
* credit: https://leetcode.com/problems/binary-prefix-divisible-by-5/discuss/266051/Java-beats-100
*/
publicList<Boolean> prefixesDivBy5(int[] A) {
List<Boolean> result = newArrayList<>(A.length);
intremainder = 0;
for (inta : A) {
remainder = ((remainder << 1) + a) % 5;
result.add(remainder == 0);
}
returnresult;
}
}
}