Skip to content

Commit af93ee5

Browse files
committed
Add solution #1015
1 parent 2e94975 commit af93ee5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,089 LeetCode solutions in JavaScript
1+
# 1,090 LeetCode solutions in JavaScript
22

33
[https://leetcode.com/](https://leetcode.com/)
44

@@ -823,6 +823,7 @@
823823
1012|[Numbers With Repeated Digits](./solutions/1012-numbers-with-repeated-digits.js)|Hard|
824824
1013|[Partition Array Into Three Parts With Equal Sum](./solutions/1013-partition-array-into-three-parts-with-equal-sum.js)|Easy|
825825
1014|[Best Sightseeing Pair](./solutions/1014-best-sightseeing-pair.js)|Medium|
826+
1015|[Smallest Integer Divisible by K](./solutions/1015-smallest-integer-divisible-by-k.js)|Medium|
826827
1022|[Sum of Root To Leaf Binary Numbers](./solutions/1022-sum-of-root-to-leaf-binary-numbers.js)|Easy|
827828
1023|[Camelcase Matching](./solutions/1023-camelcase-matching.js)|Medium|
828829
1028|[Recover a Tree From Preorder Traversal](./solutions/1028-recover-a-tree-from-preorder-traversal.js)|Hard|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1015. Smallest Integer Divisible by K
3+
* https://leetcode.com/problems/smallest-integer-divisible-by-k/
4+
* Difficulty: Medium
5+
*
6+
* Given a positive integer k, you need to find the length of the smallest positive integer n such
7+
* that n is divisible by k, and n only contains the digit 1.
8+
*
9+
* Return the length of n. If there is no such n, return -1.
10+
*
11+
* Note: n may not fit in a 64-bit signed integer.
12+
*/
13+
14+
/**
15+
* @param {number} k
16+
* @return {number}
17+
*/
18+
var smallestRepunitDivByK = function(k) {
19+
if (k % 2 === 0 || k % 5 === 0) return -1;
20+
let remainder = 0;
21+
let length = 1;
22+
23+
while (length <= k) {
24+
remainder = (remainder * 10 + 1) % k;
25+
if (remainder === 0) return length;
26+
length++;
27+
}
28+
29+
return -1;
30+
};

0 commit comments

Comments
 (0)