Skip to content

Commit d870f55

Browse files
authored
Create 1022-smallest-integer-divisible-by-k.js
1 parent bab0ae5 commit d870f55

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number} K
3+
* @return {number}
4+
*/
5+
const smallestRepunitDivByK = function(K) {
6+
if (K % 2 === 0 || K % 5 === 0) return -1;
7+
let r = 0;
8+
for (let N = 1; N <= K; ++N) {
9+
r = (r * 10 + 1) % K;
10+
if (r == 0) return N;
11+
}
12+
return -1;
13+
};

0 commit comments

Comments
 (0)