LeetCode面试题 16.02: 单词频率

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 0 0 0

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];
    }
};

Four. Processing Results

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务