码迷,mamicode.com
首页 > 其他好文 > 详细

最小的K个数

时间:2019-03-01 11:00:20      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:turn   int   least   ret   style   NPU   ast   numbers   i++   

public class Solution {
public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) { ArrayList<Integer> ret = new ArrayList<>(); if(k > input.length) return ret; PriorityQueue<Integer> minHeap = new PriorityQueue<>(); for(int i=0; i<input.length; i++){ minHeap.offer(input[i]); } while(k>0){ ret.add(minHeap.poll()); k--; } return ret; } }

 

最小的K个数

标签:turn   int   least   ret   style   NPU   ast   numbers   i++   

原文地址:https://www.cnblogs.com/zhwcs/p/10455062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!