import java.util.*; public class Solution { public List<Integer> topKFrequent(int[] nums, int k) { HashMap<Integer, Integer> numberOccur = getNumOccur(nums); PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((o1, o2) -> numberOccur.get(o1) - numberOccur.get(o2)); Set<Map.Entry<Integer, Integer>> entries = numberOccur.entrySet(); for(Map.Entry<Integer, Integer> entry:entries){ priorityQueue.add(entry.getKey()); if(priorityQueue.size()>k){ priorityQueue.poll(); } } ArrayList<Integer> result = new ArrayList<>(); for (int i = 0; i < k; i++) { result.add(priorityQueue.poll()); } Collections.reverse(result); return result; } private HashMap<Integer, Integer> getNumOccur(int[] nums) { HashMap<Integer, Integer> numberOccur = new HashMap<>(); for (int num : nums) { if (numberOccur.get(num) == null) { numberOccur.put(num, 0); } numberOccur.put(num, numberOccur.get(num) + 1); } return numberOccur; } }
相关推荐
Frequent Elements 2016.06.03 319. Bulb Switcher 343. Integer Break 268. Missing Number 144. Binary Tree Preorder Traversal 2016.06.06 94. Binary Tree Inorder Traversal 318. Maximum Product of Word ...
462 | [Minimum Moves to Equal Array Elements II](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/) | [C++](./C++/minimum-moves-to-equal-array-elements-ii.cpp) [Python](./Python/...
java lru leetcode Java相关知识 基础知识 集合 ...Elements(堆排序、桶排序) LintCode 532 Reverse Pairs(归并排序的应用)(面试题51:数组中的逆序对) LeetCode 315 Count of Smaller Numbers A
Mining Top-k Approximate Frequent Patterns,何增友,,requent pattern (itemset) mining in transactional databases is one of the most well-studied problems in data mining. One obstacle that limits the ...
并行频繁相机挖掘算法 Frequent itemset ...by efficiently partitioning the list of frequent elements list over processors. The results of experiment show that HPFP-Miner has good scalability and performanc
The exponential number of possible subgraphs makes the problem of frequent subgraph mining a challenge. The set of maximal frequent subgraphs is much smaller to that of the set of frequent subgraphs, ...
频繁图模式的挖掘的经典阅读文章。该文章介绍了频繁图模式的挖掘算法,对致力于数据挖掘和图挖掘研究的同学有所帮助。
Mining Association Rules and Frequent Itemsets
想参加acm的来看看啊 讲的很好的一本书啊 算法很经典 希望参见acm的好好读读啊
英文原版论文:fp-growth Mining Frequent Patterns without Candidate Generation:A Frequent-Pattern Tree
这是关于模式挖掘的电子书,高清,最新版本,经典著作,英文版
韩国人写的流数据分析SCI论文,2013年发表
Frequent Close Pattern Mining.ppt
这是我从国外知名大学cs专业留学的同学那里收集来的作业资料(英文原版) 【留学生作业代写资料assignment英文原版】Python作业之Frequent Itemset Mining Using MapReduce
An optimal text compression algorithm based on frequent pattern mining
广工《算法和高级数据结构教程课程设计》 Frequent Values(poj 3368) C语言实现
BIDE算法PPT, frequent sequence mining
HPFP-Miner:一种新并行化的频繁项集挖掘算法,陈晓云,何艳珊,频繁项集挖掘是数据挖掘领域的一个重要的基本问题,它可以用于多种数据挖掘的任务中。这类挖掘任务大多需要多次扫描数据库,如果
一篇流数据分析方面的经典SCI论文,2013年发表的
Frequent Subgraph Mining Based on Pregel