import java.lang.*;import java.util.ArrayList;publicclassMain{publicstaticvoidmain(String args[]){int[] a =newint[]{1,8,4,2};
Solution solution =newSolution();
System.out.println(solution.GetLeastNumbers_Solution(a,3));}}
classSolution{public ArrayList<Integer>GetLeastNumbers_Solution(int[] input,int k){if(input==null || input.length==0|| k<0|| k>input.length)returnnewArrayList<>();// Arrays.sort(input);//快排else{
ArrayList<Integer> x =newArrayList<>();int begin =0;int end = input.length;while(k>begin){for(int i = begin +1; i < end; i++)if(input[begin]> input[i]){int a =0;
a = input[i];
input[i]= input[begin];
input[begin]= a;}
begin++;}for(int i =0; i < k; i++){
x.add(input[i]);}return x;}}}