First. Problem’s Description
Second. Problem’s Solution
We can simply use a unordered_map to solve this problem, which core is powered by Hash
By the way, the default initial value is
Three. Code For Solution
class WordsFrequency {
private:
unordered_map<string, int> ump;
public:
WordsFrequency(vector<string>& book) {
for(auto it: book) ump[it]++;
}
int get(string word) {
return ump[word];
}
};