Topk问题
题目描述: 输入n个整数,找出其中最小的K个数。例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4。 解决思路: 方法一:首先不要想着使用排序。因为面试官在考察你的时候经常用大数据来考察,比如100亿之类的。应该使用堆排序,用大根堆。 import java.util.*; public class Solution { public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { ArrayList<Integer> list = new ArrayList<Integer>(); if(k > input.length || k == 0) return list; PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(k, new Comparator<Integer>() { public int compare(Int...



