Find the K-Beauty of a Number LeetCode solution in Python

1
class Solution:
2
def divisorSubstrings(self, num: int, k: int) -> int:
3
# since integer has no length function, we convert our num into a str.
4
# Then we run a loop that goes until i+k-1 < len(numStr) and take
5
# n = int(numStr[i: i+k]); and if n!=0 and num%n==0 meaning
6
# num is divisible by n so we add 1 to k_beauty and return it in the end.
7

8
numStr = str(num)
9
i, k_beauty = 0, 0
10

11
while i + k - 1 < len(numStr):
12
n = int(numStr[i : i + k])
13
if n != 0 and num % n == 0:
14
k_beauty += 1
15

16
i += 1
17

18
return k_beauty

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0