插入排序
最小的K个数
http://www.nowcoder.com/questionTerminal/6a296eb82cf844ca8539b57c23e6e9bf
class Solution { public: vector<int> GetLeastNumbers_Solution(vector<int> input, int k) { vector<int> ret; if(input.size()<=0 || k>input.size()) return ret; for(int i = 1; i<input.size();i++) { for(int j = i-1;j>=0&&input[j+1]<=input[j];j--) { swap(input[j+1], input[j]); } } for(int i = 0; i<k;i++) { ret.push_back(input[i]); } return ret; } void swap(int &a, int &b) { int temp = a; a = b; b = temp; } };