给定一个String数组,求K个出现最频繁的数。

记录一下查到的资料和思路:

1. 使用heap sorting, 先用hashmap求出单词和词频。需要额外建立一个class Node,把单词和词频都保存进去,对Node中的词频进行堆排序。Time Complexity - O(n * logk)

2. 使用index couting,也是先用hashmap求出单词和词频,再基于单词的词频进行Radix Sorting。 这种方法有很多细节还需要思考。  Time Complexity - O(n)

Reference:

http://www.capacode.com/string/k-most-frequent-items-with-linear-time-solution/

http://blog.csdn.net/v_july_v/article/details/7382693

http://www.geeksforgeeks.org/find-the-k-most-frequent-words-from-a-file/

http://yuanhsh.iteye.com/blog/2200539

Find K most Frequent items in array的更多相关文章

  1. K Closest Numbers In Sorted Array

    Given a target number, a non-negative integer k and an integer array A sorted in ascending order, fi ...

  2. 【LeetCode】1471. 数组中的 k 个最强值 The k Strongest Values in an Array (Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 自定义排序 日期 题目地址:https://leetc ...

  3. Leetcode 347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  4. leetcode347 Top K Frequent Elements

    """ Given a non-empty array of integers, return the k most frequent elements. Example ...

  5. [LeetCode] Top K Frequent Elements 前K个高频元素

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  6. LeetCode 【347. Top K Frequent Elements】

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  7. (Collection)347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  8. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  9. 347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

随机推荐

  1. 《实时控制软件设计》Git 基本操作练习

    根据老师提供的教程 对 数据库创建.提交文件.创建分支.删除分支.合并分支.冲突处理等操作进行了练习 得到log文件如下: yanbin-guo@yanbinguo MINGW64 /Git (mas ...

  2. Struts2重定向

    第一方式:  参数之间必须使用&   .&是&在xml中转义字符  <result name="error" type="redirect& ...

  3. HTML5中的Canvas精品教程

    http://javascript.ruanyifeng.com/htmlapi/canvas.html

  4. Keystore概念,Keytool工具使用

    几个概念 keystore是一个密码保护的文件,用来存储密钥和证书(也就是说,keystore中存储的有两类型entries):这个文件(默认的)位于你的home目录,也就是你登录到操作系统的用户名的 ...

  5. android开发 自定义图文混排控件

    功能:图文混排,可自动缩放字体,如图: 单点触控使用的代码来自:http://blog.csdn.net/xiaanming/article/details/42833893  谢谢博主! 在该dem ...

  6. 【WildCard Matching】cpp

    题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...

  7. 【python】正则表达式

    参考资料:http://deerchao.net/tutorials/regex/regex.htm 1.正则表达式基础 2.python 正则表达式 1.正则表达式基础 元字符: 其他语法: (1) ...

  8. 【BZOJ】【1010】【HNOI2008】玩具装箱Toy

    DP/斜率优化 根据题目描述很容易列出动规方程:$$ f[i]=min\{ f[j]+(s[i]-s[j]+i-j-1-L)^2 \}$$ 其中 $$s[i]=\sum_{k=1}^{i} c[k] ...

  9. Leetcode#147 Insertion Sort List

    原题地址 心得:有关链表的题目,多用中间变量,代码写得清晰一点,适当注释 代码: ListNode *insertionSortList(ListNode *head) { if (!head) re ...

  10. The Brain as a Universal Learning Machine

    The Brain as a Universal Learning Machine This article presents an emerging architectural hypothesis ...