-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeetCode5855.java
38 lines (34 loc) · 1011 Bytes
/
LeetCode5855.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package me.hackhub.leetcode.solution;
import java.util.Arrays;
import java.util.Comparator;
/**
* Copyright © 2017~2021 by hackhub.me
*
* @Author: mesondzh
* @Date: 2021-08-29 17:39
* @Description: https://leetcode-cn.com/problems/find-the-kth-largest-integer-in-the-array/
*/
public class LeetCode5855 {
public String errorSolution(String[] nums, int k) {
Arrays.sort(nums, Comparator.comparingInt(o -> Integer.parseInt(o, 10)));
if (nums.length - k <= 0) {
return nums[0];
}
return nums[nums.length - k];
}
public String kthLargestNumber(String[] nums, int k) {
Arrays.sort(nums, (o1, o2) -> {
if (o1.length() > o2.length()) {
return 1;
}
if (o1.length() < o2.length()) {
return -1;
}
return o1.compareTo(o2);
});
if (nums.length - k <= 0) {
return nums[0];
}
return nums[nums.length - k];
}
}