import java.util.*;
public class Solution {
private int K;
public int findKth(int[] a, int n, int K) {
// write code here
this.K = K;
quickSort(a,0,a.length-1);
return a[K-1];
}
public void quickSort(int[] a,int l, int r){
if(l>=r)
return;
int t = a[l];
int i =l;
int j = r;
while(i<j){
while(i<j&&t>=a[j]){
j--;
}
while(i<j&&t<=a[i]){
i++;
}
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
a[l] = a[i];
a[i] = t;
if(i==K-1)
return;
quickSort(a,l,i-1);
quickSort(a,i+1,r);
}
}
NC88 寻找第K大
最新推荐文章于 2022-03-06 17:08:51 发布