Skip to content

Commit cf04758

Browse files
add 1985
1 parent 85430a3 commit cf04758

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1985|[Find the Kth Largest Integer in the Array](https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1985.java) ||Medium||
1112
|1984|[Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1984.java) ||Easy||
1213
|1981|[Minimize the Difference Between Target and Chosen Elements](https://leetcode.com/problems/minimize-the-difference-between-target-and-chosen-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1981.java) ||Medium|DP|
1314
|1980|[Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1980.java) ||Medium||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class _1985 {
6+
public static class Solution1 {
7+
public String kthLargestNumber(String[] nums, int k) {
8+
PriorityQueue<String> maxHeap = new PriorityQueue<>((a, b) -> (a.length() != b.length() ? b.length() - a.length() : b.compareTo(a)));
9+
for (String num : nums) {
10+
maxHeap.offer(num);
11+
}
12+
while (k-- > 1) {
13+
maxHeap.poll();
14+
}
15+
return maxHeap.peek();
16+
}
17+
}
18+
19+
public static void main(String... args) {
20+
System.out.println("1234".compareTo("2345"));
21+
System.out.println("2345".compareTo("1234"));
22+
// System.out.println(String.valueOf(Long.MAX_VALUE).length());
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1985;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1985Test {
10+
private static _1985.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1985.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals("3", solution1.kthLargestNumber(new String[]{"3", "6", "7", "10"}, 4));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals("6", solution1.kthLargestNumber(new String[]{"3", "6", "7", "10", "8", "1", "5"}, 4));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)