有点怕笔试。如何快速查找n个关键字中出现频率最高的10个。n=30万

解决方案 »

  1.   

    也不知道这算哪门子伪代码,意思比较明了
    list<String,int> result=new ArrayList();
    Map<String,int>  countMap=new HashMap();
    int size=5000;
    int mapRecordCount=0;
    int repeat=0;for each keyWord in KeyWords
        if countMap is full then
            result add top 10 records of countMap
            clear countBank
            set mapRecordCount =0
        end         if countMap not contains keyWord then
            countMap put keyWord,0
        else
            get keyword repeat
            countMap put keyword,repeat+1
        end if
    nextsor result by desc
    take top 10 as result return
      

  2.   

    建立Trie树,同时计数!最后找到最多的10个
      

  3.   

    先排序 后统计 排序时间复杂度是nlgn 统计时间复杂度是n 
    最后时间复杂度就是nlgn