[
array
math
]
Leetcode 1018. Binary Prefix Divisible By 5
Problem statement
https://leetcode.com/problems/binary-prefix-divisible-by-5/
Solution
Start from the start of our array and evaluate reminder of prefix when we divide by 5
.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def prefixesDivBy5(self, nums):
x, ans = 0, []
for val in nums:
x = 2 * x + val
ans += [x % 5 == 0]
return ans