Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf04758

Browse files
add 1985
1 parent85430a3 commitcf04758

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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||
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.PriorityQueue;
4+
5+
publicclass_1985 {
6+
publicstaticclassSolution1 {
7+
publicStringkthLargestNumber(String[]nums,intk) {
8+
PriorityQueue<String>maxHeap =newPriorityQueue<>((a,b) -> (a.length() !=b.length() ?b.length() -a.length() :b.compareTo(a)));
9+
for (Stringnum :nums) {
10+
maxHeap.offer(num);
11+
}
12+
while (k-- >1) {
13+
maxHeap.poll();
14+
}
15+
returnmaxHeap.peek();
16+
}
17+
}
18+
19+
publicstaticvoidmain(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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1985;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1985Test {
10+
privatestatic_1985.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1985.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals("3",solution1.kthLargestNumber(newString[]{"3","6","7","10"},4));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals("6",solution1.kthLargestNumber(newString[]{"3","6","7","10","8","1","5"},4));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp