根据题目的hint,使用单层循环计算:

 1 class Solution(object):
 2     def prefixesDivBy5(self, A: 'List[int]') -> 'List[bool]':
 3         n = len(A)
 4         result = list()
 5         preNum = 0
 6         for i in range(n):
 7             binNum = A[i]
 8             X = preNum * 2 + binNum
 9             if X % 5 == 0:
10                 result.append(True)
11             else:
12                 result.append(False)
13             preNum = X
14         return result

 

posted on 2019-03-31 14:38  Sempron2800+  阅读(176)  评论(0编辑  收藏  举报