class WordsFrequency {
private HashMap<String,Integer> map=new HashMap<>();
// private HashMap<String, Integer> map = new HashMap<>();
public WordsFrequency(String[] book) {
for(String str :book){
map.put(str,map.getOrDefault(str,0)+1);
}
}
public int get(String word) {
return map.getOrDefault(word,0);
}
}
/**
* Your WordsFrequency object will be instantiated and called as such:
* WordsFrequency obj = new WordsFrequency(book);
* int param_1 = obj.get(word);
*/
面试题 16.02. 单词频率 哈希表
最新推荐文章于 2022-10-26 22:00:54 发布