寻找第k大的数
寻找第K大
https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf?tpId=188&&tqId=38572&rp=1&ru=/activity/oj&qru=/ta/job-code-high-week/question-ranking
function findKth( a , n , K ) {
return quickfind(a, 0, n - 1, K);
}
function quickfind(a, left, right, k) {
let i = left, j = right, pivot = a[left];
while (i < j) {
while (i < j && a[j] >= pivot) j--;
if (i < j) a[i++] = a[j];
while (i < j && a[i] <= pivot) i++;
if (i < j) a[j--] = a[i];
}
a[i] = pivot;
const deltaK = k - right + i - 1;
if (deltaK === 0) return pivot;
else if (deltaK > 0) return quickfind(a, left, i - 1, deltaK);
else return quickfind(a, i + 1, right, k);
}