Skip to content

Commit

Permalink
refactor 1492
Browse files Browse the repository at this point in the history
  • Loading branch information
fishercoder1534 committed Jun 27, 2020
1 parent d525bfa commit c08f4ad
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★

| # | Title | Solutions | Video | Difficulty | Tag
|-----|----------------|---------------|--------|-------------|-------------
|1492|[The kth Factor of n](https://leetcode.com/problems/the-kth-factor-of-n/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1492.java) | |Medium|Math|
|1491|[Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1491.java) | |Easy|Array, Sort|
|1487|[Making File Names Unique](https://leetcode.com/problems/making-file-names-unique/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1487.java) | |Medium|HashTable, String|
|1486|[XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1486.java) | |Medium|Array, Bit Manipulation|
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/fishercoder/solutions/_1492.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

public class _1492 {
public static class Solution1 {
public int kthFactor(int n, int k) {
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
list.add(i);
}
}
return list.size() >= k ? list.get(k - 1) : -1;
}
}
}
22 changes: 22 additions & 0 deletions src/test/java/com/fishercoder/_1492Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.fishercoder;

import com.fishercoder.solutions._1492;
import org.junit.BeforeClass;
import org.junit.Test;

import static junit.framework.TestCase.assertEquals;

public class _1492Test {
private static _1492.Solution1 solution1;

@BeforeClass
public static void setup() {
solution1 = new _1492.Solution1();
}

@Test
public void test1() {
assertEquals(3, solution1.kthFactor(12, 3));
}

}

0 comments on commit c08f4ad

Please sign in to comment.