[LeetCode] Find the Kth Largest Integer in the Array

1985. Find the Kth Largest Integer in the Array

You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.

Return the string that represents the kth largest integer in nums.

Note: Duplicate numbers should be counted distinctly. For example, if nums is [“1”,”2”,”2”], “2” is the first largest integer, “2” is the second-largest integer, and “1” is the third-largest integer.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
string kthLargestNumber(vector<string>& A, int k) {
sort(begin(A), end(A), [](auto a, auto b) {
if(a.length() == b.length()) return a > b;
return a.length() > b.length();
});
return A[k-1];
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/07/11/PS/LeetCode/find-the-kth-largest-integer-in-the-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.