快速排序(效果最好)
import java.util.*;
public class Solution {
public int findKth(int[] a, int n, int K) {
// write code here
quickSort(a, 0, n - 1);
return a[n - K];
}
public void quickSort(int[] arr, int left, int right) {
if (left >= right) return;
int i = left;
int j = right;
int tmp = arr[left];
while (i < j) {
while (i < j && arr[j] >= tmp) j--;
while (i < j && arr[i] <= tmp) i++;
if (i < j) {
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
arr[left] = arr[i];
arr[i] = tmp;
quickSort(arr, left, i - 1);
quickSort(arr, i + 1, right);
}
}