var findKthLargest = function (nums, k) {
// 快速排序
function sort(nums, Left, Right) {
let l = Left;
let r = Right;
let pivot = nums[l];
if (l >= r) return;
while (l < r) {
while (nums[r] >= pivot && l < r) {
r--;
}
if (nums[r] < pivot) {
nums[l] = nums[r];
l++;
}
while (nums[l] <= pivot && l < r) {
l++;
}
if (nums[l] > pivot) {
nums[r] = nums[l];
r--;
}
if (l === r) {
nums[l] = pivot
}
}
sort(nums, Left, l - 1);
sort(nums, r + 1, Right);
}
sort(nums,0,nums.length-1);
nums
return nums.reverse()[k-1]
};
复制代码