题解 | #最小的K个数#
最小的K个数
http://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf
import java.util.ArrayList; import java.util.stream.Stream; import java.util.stream.Collectors; import java.util.Arrays; public class Solution { public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { Arrays.sort(input); return Arrays.stream(input).limit(k).boxed().collect(Collectors.toCollection(ArrayList<Integer>::new)); } }
面向API编程,两行代码解决问题