Skip to content

Commit 4bfffec

Browse files
Merge pull request #1 from ArsiyaTasleem90250/ArsiyaTasleem90250-patch-1
Create smallestRepunitDivByK.java
2 parents 4d3622a + 48e88f7 commit 4bfffec

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

smallestRepunitDivByK.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int smallestRepunitDivByK(int k) {
3+
if(k == 2 || k == 5)
4+
{
5+
return -1;
6+
}
7+
8+
int rem = 0;
9+
for(int length = 1; length<=k; length++)
10+
{
11+
rem = (rem*10 + 1) % k; // simulate adding a '1'
12+
if(rem == 0)
13+
{
14+
return length;
15+
}
16+
}
17+
return -1;
18+
}
19+
}

0 commit comments

Comments
 (0)