Skip to content

Commit dc4d9a9

Browse files
committed
Time: 4 ms (62.16%), Space: 19.3 MB (13.32%) - LeetHub
1 parent 28d7631 commit dc4d9a9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def prefixesDivBy5(self, nums: List[int]) -> List[bool]:
8+
answer = list()
9+
prefix = 0
10+
for num in nums:
11+
prefix = ((prefix << 1) + num) % 5
12+
answer.append(prefix == 0)
13+
return answer
14+
15+
16+
nums = [0, 1, 1]
17+
print(Solution().prefixesDivBy5(nums))
18+
nums = [1, 1, 1]
19+
print(Solution().prefixesDivBy5(nums))

0 commit comments

Comments
 (0)