Skip to content

Commit

Permalink
Time: 0 ms (100.00%), Space: 39 MB (87.87%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
tausiq2003 committed Oct 9, 2023
1 parent f19dab1 commit 446a039
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 1492-the-kth-factor-of-n/1492-the-kth-factor-of-n.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public int kthFactor(int n, int k) {
if (k < 1 || k > n) {
return -1;
}

int count = 0;

for (int i = 1; i <= n; i++) {
if (n % i == 0) {
count++;
if (count == k) {
return i;
}
}
}

return -1;
}}

0 comments on commit 446a039

Please sign in to comment.