Skip to content

Commit 32727a1

Browse files
committed
1018. Binary Prefix Divisible By 5
1 parent 83491b1 commit 32727a1

File tree

1 file changed

+30
-0
lines changed
  • Binary Prefix Divisible By 5

1 file changed

+30
-0
lines changed

Binary Prefix Divisible By 5/kata.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution(object):
2+
def prefixesDivBy5(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: List[bool]
6+
"""
7+
result = [False] * len(nums)
8+
tracker = 1
9+
i = 0
10+
for i, num in enumerate(nums):
11+
if num != 0:
12+
break
13+
else:
14+
result[i] = True
15+
16+
i += 1
17+
for num in nums[i:]:
18+
if num == 0:
19+
tracker = tracker << 1
20+
if tracker % 5 == 0:
21+
result[i] = True
22+
else:
23+
tracker = tracker << 1
24+
tracker = tracker | 1
25+
if tracker % 5 == 0:
26+
result[i] = True
27+
i += 1
28+
29+
return result
30+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy