Skip to content

Instantly share code, notes, and snippets.

@wushbin
Created April 1, 2020 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wushbin/44c5645d7ef74f84b1f183c72a07891a to your computer and use it in GitHub Desktop.
Save wushbin/44c5645d7ef74f84b1f183c72a07891a to your computer and use it in GitHub Desktop.
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