Skip to content

Commit 8545177

Browse files
committed
Time: 11 ms (53.34%), Space: 17.6 MB (99.16%) - LeetHub
1 parent c6063fb commit 8545177

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# time complexity: O(k)
2+
# space complexity: O(1)
3+
class Solution:
4+
def smallestRepunitDivByK(self, k: int) -> int:
5+
remainder = 0
6+
for num in range(1, k+1):
7+
remainder = (remainder*10+1) % k
8+
if remainder == 0:
9+
return num
10+
return -1
11+
12+
13+
k = 1
14+
print(Solution().smallestRepunitDivByK(k))
15+
k = 2
16+
print(Solution().smallestRepunitDivByK(k))
17+
k = 3
18+
print(Solution().smallestRepunitDivByK(k))
19+
k = 7
20+
print(Solution().smallestRepunitDivByK(k))
21+
k = 70
22+
print(Solution().smallestRepunitDivByK(k))

0 commit comments

Comments
 (0)