File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 171
171
1475|[ Final Prices With a Special Discount in a Shop] ( ./1475-final-prices-with-a-special-discount-in-a-shop.js ) |Easy|
172
172
1480|[ Running Sum of 1d Array] ( ./1480-running-sum-of-1d-array.js ) |Easy|
173
173
1486|[ XOR Operation in an Array] ( ./1486-xor-operation-in-an-array.js ) |Easy|
174
+ 1492|[ The kth Factor of n] ( ./1492-the-kth-factor-of-n.js ) |Medium|
174
175
1496|[ Path Crossing] ( ./1496-path-crossing.js ) |Easy|
175
176
1598|[ Crawler Log Folder] ( ./1598-crawler-log-folder.js ) |Easy|
176
177
1780|[ Check if Number is a Sum of Powers of Three] ( ./1780-check-if-number-is-a-sum-of-powers-of-three.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1492. The kth Factor of n
3
+ * https://leetcode.com/problems/the-kth-factor-of-n/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given two positive integers n and k.
7
+ *
8
+ * A factor of an integer n is defined as an integer i where n % i == 0.
9
+ *
10
+ * Consider a list of all factors of n sorted in ascending order, return
11
+ * the kth factor in this list or return -1 if n has less than k factors.
12
+ */
13
+
14
+ /**
15
+ * @param {number } n
16
+ * @param {number } k
17
+ * @return {number }
18
+ */
19
+ var kthFactor = function ( n , k ) {
20
+ for ( let i = 1 ; i <= n ; i ++ ) {
21
+ if ( n % i === 0 ) {
22
+ k -- ;
23
+ }
24
+ if ( ! k ) return i ;
25
+ }
26
+ return - 1 ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments