解题思路:
(1)每次只需要保留当前位置的余数即可,因为其它均可以整除5
class Solution {
public:
vector<bool> prefixesDivBy5(vector<int>& A) {
int n = 0;
std::vector<bool> res(A.size());
for (int i = 0; i < A.size(); i++) {
// updating n to the next value in base 10
n = (n * 2 + A[i]) % 5;
// updating res
res[i] = !n;
}
return res;
}
};