题解 | #最小的K个数#
最小的K个数
http://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf
import java.util.ArrayList;
public class Solution {
public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) {
sort(input);
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<k;i++){
list.add(input[i]);
}
return list;
}
public int[] sort(int [] input){
for(int i = 0; i<input.length-1; i++){
for(int j = i+1; j<input.length; j++){
if(input[j]<input[i]){
int k = input[i];
input[i] = input[j];
input[j] = k;
}
}
}
return input;
}
}