网址:https://leetcode.com/problems/binary-prefix-divisible-by-5/
一次for循环遍历数组,在上次计算的基础上得到本次的结果!
class Solution {
public:
vector<bool> prefixesDivBy5(vector<int>& A)
{
vector<bool> ans;
int num = ;
int pre_num = ;
for(int i=; i<A.size(); i++)
{
num = ;
num += pre_num * + A[i];
num = num % ;
pre_num = num;
if(num % == )
{
ans.push_back(true);
}
else
ans.push_back(false);
}
return ans;
}
};