Skip to content

Commit 5c743f2

Browse files
authored
Create 1015. Smallest Integer Divisible by K (#942)
2 parents d0231f5 + 1638ca0 commit 5c743f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int smallestRepunitDivByK(int k) {
4+
if (k % 2 == 0 || k % 5 == 0) return -1;
5+
int r = 0;
6+
for (int i = 1; i <= k; i++) {
7+
r = (r * 10 + 1) % k;
8+
if (r == 0) return i;
9+
}
10+
return -1;
11+
}
12+
};

0 commit comments

Comments
 (0)