Skip to content

Commit be33ea2

Browse files
authored
Create find-the-k-beauty-of-a-number.py
1 parent 04cacb5 commit be33ea2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(logn)
2+
# Space: O(logn)
3+
4+
# sliding window
5+
class Solution(object):
6+
def divisorSubstrings(self, num, k):
7+
"""
8+
:type num: int
9+
:type k: int
10+
:rtype: int
11+
"""
12+
result = curr = 0
13+
s = map(int, str(num))
14+
base = 10**(k-1)
15+
for i, x in enumerate(s):
16+
if i-k >= 0:
17+
curr -= s[i-k]*base
18+
curr = curr*10+x
19+
if i+1 >= k:
20+
result += int(curr and num%curr == 0)
21+
return result

0 commit comments

Comments
 (0)