Created
April 1, 2020 05:08
-
-
Save wushbin/44c5645d7ef74f84b1f183c72a07891a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int smallestRepunitDivByK(int K) { | |
if (K == 2 || K == 5) { | |
return -1; | |
} | |
int num = 0; | |
for (int i = 1; i <= K; i++) { | |
num = (num * 10 + 1) % K; | |
if (num == 0) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment