给定一个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. 带搜索框的下拉框chosen.jQury.js

    下载所需js,css png资源     <link href="chosen.css" rel="stylesheet" type="text ...

  2. 【收藏】Linux添加/删除用户和用户组

    1.建用户: adduser phpq                             //新建phpq用户 passwd phpq                               ...

  3. Linux 下的类似Windows下Everything的搜索工具

    Windows NTFS有个超级快的搜索工具Everything,非常好用,Linux下有几个类似的命令行工具,太难用了,推荐一个catfish,类似Everything,有GUI,可以自定义一个快捷 ...

  4. 对中级Linux用户有用的20个命令

    1. 命令: Find 搜索指定目录下的文件,从开始于父目录,然后搜索子目录. 注意: -name‘选项是搜索大小写敏感.可以使用-iname‘选项,这样在搜索中可以忽略大小写.(*是通配符,可以搜索 ...

  5. IBM MQ消息中间件jms消息中RHF2消息头的处理

    公司的技术平台在和某券商对接IBM MQ消息中间件时,发送到MQ中的消息多出了消息头信息:RHF2,造成消息的接收处理不正常.在此记录此问题的处理方式. 在IBM MQ中提供了一个参数 targetC ...

  6. 《我是一只IT小小鸟》阅读笔记

    <我是一只IT小小鸟>,这本书对我来说,有可能我现在并不懂得那其中的道理,但是,我觉得它写的很好,很现在的我很相似,但是在里面,我看到了他们都在说,一开始可能并不对IT这门课有很深的见解, ...

  7. Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树

    题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...

  8. 【BZOJ】【1597】【USACO 2008 Mar】土地购买

    DP/斜率优化 Orz Hzwer…… 想到排序了,但没想到其实可以将序列转化为x递增且y递减的序列……因为x是递增的,若y[i]>y[i-1]那么第i-1个就足够小……以至于可以在搞定第 i ...

  9. Leetcode#92 Reverse Linked List II

    原题地址 第一步,找到将要翻转的位置,记录翻转部分前一个节点(prev) 第二步,翻转,记录翻转完成后这部分的首(reverseHead)和尾(reverseTail),以及翻转部分之后的一个节点(p ...

  10. 【翻译】Sencha Touch2.4 The Layout System 布局

    [翻译]The Layout System 布局 In Sencha Touch there are two basic building blocks: componentsand containe ...