https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/submissions/
class Solution {
public:
void topk(int start,int end,int k,vector<int>& arr){
if(start>=end)
return;
int l=start;
int r=end;
int temp=arr[l];
while(l<r){
while(r>l && arr[r]>=temp){
r--;
}
arr[l]=arr[r];
while(l<r && arr[l]<=temp){
l++;
}
arr[r]=arr[l];
}
arr[l]=temp;
if(k<l){
topk(start,l-1,k,arr);
}
else if(k>l){
topk(l+1,end,k,arr);
}
}
vector<int> getLeastNumbers(vector<int>& arr, int k) {
topk(0,arr.size()-1,k,arr);
vector<int> ans;
for(int i=0;i<k;i++)
ans.push_back(arr[i]);
return ans;
}
};