堆排序
class Finder {
public:
int findKth(vector<int> a, int n, int K) {
// write code here
//假设int myints[] = {10,20,30,5,15};
//建立最大堆,会使得a[n-1]放的是最大值30
make_heap(a.begin(),a.end());
//在已经建立好的堆上面,进行堆排序,使得5,10,15,20,30
sort_heap(a.begin(),a.end());
return a[n-K];
}
}; 
京公网安备 11010502036488号