根据题目的hint,使用单层循环计算:
class Solution(object):
def prefixesDivBy5(self, A: 'List[int]') -> 'List[bool]':
n = len(A)
result = list()
preNum = 0
for i in range(n):
binNum = A[i]
X = preNum * 2 + binNum
if X % 5 == 0:
result.append(True)
else:
result.append(False)
preNum = X
return result