哈希表 单词在任意一本书中出现的频率表

package com.NodePair;
import java.util.HashMap;

public class Frequency {
HashMap setupDictionary(String[] book)
{
HashMap table=new HashMap();
for(String s:book)
{
s=s.toLowerCase();
if(!table.containsKey(s))
{
table.put(s,0);
}
table.put(s, table.get(s)+1);
}
return table;
}


int getFrequency(HashMap table,String word)
{
if(table==null||word==null)
return -1;
word=word.toLowerCase();
if(table.containsKey(word))
{
return table.get(word);
}
return 0;
}
}

你可能感兴趣的:(cracking,the,coding,interview)