题解 | #JAVA最小的K个数#
最小的K个数
http://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf
14ms:击败76%
900kb:击败96%
import java.util.*; import java.util.ArrayList; public class Solution { public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { Arrays.sort(input); if(k>input.length)k=-1; ArrayList<Integer> arr=new ArrayList<>(); for (int i = 0; i < k; i++) { arr.add(input[i]); } return arr; } }