Top K 问题
作者:
三分归元币 | 来源:发表于
2020-07-10 22:02 被阅读0次public class Application {
public static void main(String[] args) throws Exception{
List<Integer> list = new ArrayList<>();
Random r = new Random();
int max = Integer.MIN_VALUE;
for(int i=0;i<1000;i++){
int value = r.nextInt(10000);
max = Math.max(max,value);
list.add(value);
}
PriorityQueue<Integer> queue = new PriorityQueue<>(10);
for(int v : list){
queue.offer(v);
if(queue.size() > 10){
queue.poll();
}
}
System.out.println("max = "+max);
while (!queue.isEmpty()){
System.out.println(queue.poll());
}
}
}
本文标题:Top K 问题
本文链接:https://www.haomeiwen.com/subject/tnevcktx.html
网友评论