1018. 可被 5 整除的二进制前缀
思路一:逐位模拟
因为每次左移=*2,所以我们下一次更新为tmp = (tmp%5)*2+A[i]
。
class Solution {
public List<Boolean> prefixesDivBy5(int[] A) {
List<Boolean> res = new ArrayList<Boolean>();
int tmp=0;
for(int i=0;i<A.length;i++){
tmp = (tmp%5)*2+A[i];
res.add((tmp%5)==0);
}
return res;
}
}