• 简单选择排序

public class Solution {
    public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) {
        int minIndex = 0;
        int temp = 0;
        ArrayList<Integer> returnList = new ArrayList<>();
        for(int i = 0; i < k; i++){
            minIndex = i;
            for(int j = i+1; j< input.length; j++){
                if(input[minIndex] >= input[j]){
                    minIndex = j;
                }
            }
            returnList.add(input[minIndex]);
            temp = input[i];
            input[i] = input[minIndex];
            input[minIndex] = temp;
        }
        
        return returnList;
    }
}