题解 | #最小的K个数#
最小的K个数
http://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf
import java.util.ArrayList; import java.util.*; public class Solution { public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { ArrayList<Integer> list = new ArrayList<Integer>(); ArrayList<Integer> rs = new ArrayList<Integer>(); for(int i = 0; i<input.length; i++){ list.add(input[i]); } list.sort(Comparator.naturalOrder()); for(int i = 0; i< k;i++){ rs.add(list.get(i)); } return rs; } }