1、快速排序
private void quickSort(int[] a, int begin, int end){
if(begin>end) return;
int k = a[begin];
int i=begin;
int j=end;
while(i<j){
while(a[j]>=k&&i<j) j--;
if(i<j) a[i++] = a[j];
while(a[i]<k&&i<j) i++;
if(i<j) a[j--] = a[i];
}
a[i] = k;
quickSort(a,begin,i-1);
quickSort(a,i+1,end);
}
2、优先队列
class Solution {
public int findKthLargest(int[] nums, int k) {
PriorityQueue<Integer> queue = new PriorityQueue<>((a,b) -> b-a);
for(int i=0;i<nums.length;i++){
queue.offer(nums[i]);
}
for(int i=0;i<k-1;i++){
queue.poll();
}
return queue.poll();
}
}