笨法,排序输出哈哈
import java.util.*; public class Solution { public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { ArrayList<Integer> ans = new ArrayList<>(); if(k>input.length){ return ans; } Arrays.sort(input); for(int i=0;i<k;i++){ ans.add(input[i]); } return ans; } }