File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,089 LeetCode solutions in JavaScript
1
+ # 1,090 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcode.com/ ] ( https://leetcode.com/ )
4
4
823
823
1012|[ Numbers With Repeated Digits] ( ./solutions/1012-numbers-with-repeated-digits.js ) |Hard|
824
824
1013|[ Partition Array Into Three Parts With Equal Sum] ( ./solutions/1013-partition-array-into-three-parts-with-equal-sum.js ) |Easy|
825
825
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|
826
827
1022|[ Sum of Root To Leaf Binary Numbers] ( ./solutions/1022-sum-of-root-to-leaf-binary-numbers.js ) |Easy|
827
828
1023|[ Camelcase Matching] ( ./solutions/1023-camelcase-matching.js ) |Medium|
828
829
1028|[ Recover a Tree From Preorder Traversal] ( ./solutions/1028-recover-a-tree-from-preorder-traversal.js ) |Hard|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments