import java.util.*; public class Solution { public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { ArrayList<Integer> list = new ArrayList(); quickSort(input,0,input.length-1); if(k<=input.length){ for(int i=0;i<k;i++){ list.add(input[i]); } } return list; } public void quickSort(int [] arr,int low,int high){ int i,j,temp; if(low>high){ return; } i = low; j = high; temp = arr[low]; while(i<j){ while(i<j && temp <= arr[j]){ j--; } while(i<j && temp >= arr[i]){ i++; } if(i<j){ int tmp = arr[j]; arr[j] = arr[i]; arr[i] = tmp; } } arr[low] = arr[i]; arr[i] = temp; quickSort(arr,low,i-1); quickSort(arr,i+1,high); } }