Skip to content

Commit 0790500

Browse files
authored
Create find-the-kth-largest-integer-in-the-array.cpp
1 parent 3a79a63 commit 0790500

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n) ~ O(n^2), O(n) on average
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
string kthLargestNumber(vector<string>& nums, int k) {
7+
nth_element(begin(nums), begin(nums) + k - 1, end(nums),
8+
[](const auto& a, const auto& b) {
9+
return size(a) == size(b) ? a > b : size(a) > size(b);
10+
});
11+
return nums[k - 1];
12+
}
13+
};

0 commit comments

Comments
 (0)