You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on the LCP string comparison algorithm you provided, it should be more clear to use a selection algorithm instead of the sorting on the whole array.
string kthLargestNumber(vector<string>& nums, int k) {
nth_element(nums.begin(), nums.begin() + k - 1, nums.end(), [](auto& a, auto& b) {
// return true if a is lexicographical larger than b.int N = a.size(), M = b.size();
if (N > M) returntrue;
if (N < M) returnfalse;
for (int i = 0; i < N; ++i) {
if (a[i] != b[i])
return a[i] > b[i];
}
returnfalse;
});
return nums[k-1];
}
The text was updated successfully, but these errors were encountered:
charmhe
changed the title
[1985] Comments
[1985] Comments on The Choice of Sorting
Mar 9, 2022
Based on the LCP string comparison algorithm you provided, it should be more clear to use a selection algorithm instead of the sorting on the whole array.
The text was updated successfully, but these errors were encountered: