剑指OFFER 最小的k个数
使用了优先队列
class Solution {
public:
vector<int> GetLeastNumbers_Solution(vector<int> input, int k) {
vector<int> res;
if(k == input.size())return input;
if(k > input.size())
{
return res;
}
priority_queue<int,vector<int>,greater<int>> que;
for(int i=0;i<input.size();i++)
{
que.push(input[i]);
}
for(int i=0;i<k;i++)
{
res.push_back(que.top());
que.pop();
}
return res;
}
};