原题链接

考察模运算公式:

(a + b) % n = (a % n + b % n) % n;

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
vector<bool> prefixesDivBy5(vector<int>& A) {
int x = 0;
vector<bool> ans;
for(int i=0;i<A.size();i++) {
x = ((x<<1)+A[i])%5;
ans.push_back(x==0);
}
return ans;
}
};