【发布时间】:2013-09-26 23:59:11
【问题描述】:
好的,
我在大量采访中都遇到过这个问题,我想我需要一些帮助来解决它。
您有大量的 URL 作为字符串数组或从文件中读取。您现在需要获取前 10 个阅读次数最多的内容,如文件中前 10 个最常用的 URL。
我的做法是:
Read them into a String Array,
Iterate through each String/URL,
At every Iteration, put them into Hashtable, incrementing the count.
Iterate again and find feed the scores into an array
Sort and find the top 10 scores OR use max-heap to get the top 10.
Iterate again and remove the URL's with the top 10 scores.
这是一个非常糟糕的答案吗?有人可以进一步帮助我吗?
【问题讨论】:
-
相关问题,虽然它是跨网络的 - Find Top 10 Most Frequent visited URL, data is stored across network。
-
另一个相关问题 - Getting top 100 URL from a log file.
-
仅当 Unix
sort file.txt | uniq -c | sort -rn | head
标签: string algorithm url data-structures